Ejemplo n.º 1
0
        public async void Test1()
        {
            var options = new DbContextOptionsBuilder <SMarketContext>()
                          .UseInMemoryDatabase(databaseName: "TestDBMarket")
                          .Options;

            using (var context = new SMarketContext(options))
            {
                UnitType unitType = new UnitType();
                unitType.Symbol      = "KG";
                unitType.Description = "KiloGramo";

                var           service = new UnitTypesController(context);
                IActionResult post    = await service.PostUnitType(unitType);
            }

            using (var context = new SMarketContext(options))
            {
                List <UnitType> listUnitTypes = await context.UnitType.ToListAsync();

                int count = listUnitTypes.Count;
                Console.WriteLine("ValorCounte:" + count);
                Assert.Equal(2, count);
                //Assert.AreEqual("http://sample.com", context.Blogs.Single().Url);
            }

            // Use a separate instance of the context to verify correct data was saved to database
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            var claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", _userId.ToString());

            Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> {
                claim
            }));

            var connectionString = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString;

            _context = new DataContext(connectionString);

            _facade = new UnitTypeFacade(_context, new UnitTypeValidator());

            ODataHelper oDataHelper = new ODataHelper();

            _controller         = new UnitTypesController(oDataHelper, _facade);
            _controller.Request = new HttpRequestMessage();
            _controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            // Setting the URI of the request here is needed for the API POST method to work
            _controller.Request.RequestUri = new Uri("http://tempuri.com");

            /*
             * TODO: akrone - Taking on some Techincal Debt doing this, but pulling the Seeder into it's own project would need to
             *      be merged into other development work going on for sprint 60
             */
            Seeder.SeedWithTestData(_context);
        }