locked
Lightswitch unit tests using ServerApplicationContext RRS feed

  • Question

  • Hello,

    I want to use ServerApplicationContext to unit test Lightswitch entities. But I get an error something like "...cannot find HttpContext..." from within my unit tests. How can I mock the HttpContext?

    Saturday, June 20, 2015 3:36 PM

Answers

All replies

  • Is this what you are looking for? Hard to really know in this case. Tell us a bit more about this case.

    HttpContext.Current Property

    Global ASAX - get the server name

    Saturday, June 20, 2015 8:12 PM
  • Http://Blog.pragmaswitch.com/? p=1733

    paul van bladel ==independent enterprise application architect== http://blog.pragmaswitch.com

    Sunday, June 21, 2015 7:01 AM
  • Amazing! Thanks Paul.
    Monday, June 22, 2015 12:09 AM
  • This is a simple Test Method working with Paul's Procedure:

    [TestMethod]
            [HostType("ASP.NET")]
            [UrlToTest("http://localhost:53015/Test.aspx")]
            [AspNetDevelopmentServerHost(@"C:\TfsLocalWorkSpace02\VCA\FametalEasy\FametalEasy\bin\Debug")]
    
            public void CreateCustomer_ProvidingBasicData_IdIsNotNull()
            {
                using (ServerApplicationContext ctx = ServerApplicationContext.CreateContext())
                {
                    var cliente = ctx.DataWorkspace.ApplicationData.VcaClientes.AddNew();
    
                    cliente.CodigoLegal = "20100304005";
                    cliente.RazonSocial = "Promotores Electricos";
                    cliente.NombreComercial = "PROMELSA";
    
                    ctx.DataWorkspace.ApplicationData.SaveChanges();
    
                    Assert.AreNotEqual(0, cliente.Id);
                }
            }

    The goal would be to Unit Test the Business Logic using this approach.

    I hope that Microsoft does not let Lightswitch die and continues developing this great tool!


    Tuesday, June 30, 2015 7:09 PM