Esempio n. 1
0
        public void Setup()
        {
            var builder = new ConfigurationBuilder()
                          .AddEnvironmentVariables();

            _configuration = builder.Build();

            var options = new DbContextOptionsBuilder <LorryMobileAPIContext>()
                          .UseInMemoryDatabase(databaseName: "LorryLog")
                          .Options;

            _context    = new LorryMobileAPIContext(options);
            _controller = new PickupsController(_context);
        }
        public void Get_EndGameSession_with_id_4_returns_EndGameSession_object_with_id_4()
        {
            var data = new List <Pickup>
            {
                GetTestPickup(),
            }.AsQueryable();

            Mock <PGDbContext> context = GetTestPickupContext(data);

            var controller             = new PickupsController(context.Object);
            IHttpActionResult response = controller.GetPickup(1);

            Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <Pickup>), "GetPickup should return OK with Pickup data");

            OkNegotiatedContentResult <Pickup> responseWithData = (OkNegotiatedContentResult <Pickup>)response;

            Assert.IsNotNull(responseWithData.Content, "Pickup data that was fetched with Get should not be null");
            Assert.AreEqual(1, responseWithData.Content.PickupId, "Pickup data ID should be 1");
        }
        public void Get_Pickups_returns_all_in_database()
        {
            var data = new List <Pickup>
            {
                GetTestPickup(),
                GetTestPickup(),
            }.AsQueryable();

            Mock <PGDbContext> context = GetTestPickupContext(data);

            PickupsController controller      = new PickupsController(context.Object);
            List <Pickup>     endGameSessions = controller.GetPickups();

            Assert.AreEqual(2, endGameSessions.Count);
            foreach (var item in endGameSessions)
            {
                Assert.IsNotNull(item, "All Pickups that were fethed by Get shouldnt be null");
            }
        }