Example #1
0
        public void PutCar_ShouldFail_WhenDifferentID()
        {
            var carsTestData = new List <EmployeeCar>()
            {
                new EmployeeCar {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeCar {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeCar {
                    Id = 3, EmployeeId = 3
                }
            };
            var cars      = MockHelper.MockDbSet(carsTestData);
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeCars).Returns(cars.Object);
            dbContext.Setup(d => d.Set <EmployeeCar>()).Returns(cars.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            IDbContextFactory fac = factory.Object;
            var controller        = new EmployeeCarsController(fac);

            EmployeeCar car = new EmployeeCar {
                Id = 1, Capacity = 333, Deleted = null, EmployeeId = 1
            };
            var badresult = controller.PutEmployeeCar(999, car.ToDTO());

            Assert.IsInstanceOfType(badresult, typeof(BadRequestResult));
        }
Example #2
0
        public void PutCar_ShouldReturnOk()
        {
            var carsTestData = new List <EmployeeCar>()
            {
                new EmployeeCar {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeCar {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeCar {
                    Id = 3, EmployeeId = 3
                }
            };
            var cars      = MockHelper.MockDbSet(carsTestData);
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeCars).Returns(cars.Object);
            dbContext.Setup(d => d.Set <EmployeeCar>()).Returns(cars.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            IDbContextFactory fac = factory.Object;
            var controller        = new EmployeeCarsController(fac);

            EmployeeCar car = new EmployeeCar {
                Id = 4, Capacity = 33, Deleted = null, EmployeeId = 1
            };

            var result = controller.PutEmployeeCar(4, car.ToDTO()) as OkNegotiatedContentResult <EmployeeCarDTO>;

            // EmployeeCarDTO dto = result.Content;

            Assert.IsNotNull(result);
            Assert.AreEqual(33, (int)result.Content.Capacity);
            Assert.AreEqual(4, result.Content.Id);
            Assert.AreEqual(1, result.Content.EmployeeId);
        }