public void TestGetAllCarsForUserWithId_WithUserIdNull_ShouldReturnZeroCarsForTheUserWithIdNull() { // Arrange var contextFactory = new ApplicationDbContextFactory(); var context = contextFactory.CreateApplicationDbContext(); var mapperFactory = new AutoMapperFactory(); var mapper = mapperFactory.CreateMapper(); var carServices = new CarServices(context, mapper); SeedDbWithUsers(context); SeedDbWithCars(context); SeedCarsToTheFirstUser(context); // Act var count = carServices.GetAllCarsForUserWithId(null).Count(); var expectedCount = 0; var actualCount = count; // Assert Assert.Equal(expected: expectedCount, actual: actualCount); }
public void TestGetAllCarsForUserWithId_WithTestData_ShouldReturnAllCarsForTheUserWithId() { // Arrange var contextFactory = new ApplicationDbContextFactory(); var context = contextFactory.CreateApplicationDbContext(); var mapperFactory = new AutoMapperFactory(); var mapper = mapperFactory.CreateMapper(); var carServices = new CarServices(context, mapper); SeedDbWithUsers(context); SeedDbWithCars(context); SeedCarsToTheFirstUser(context); var firstUser = context.Users.FirstOrDefault(); // Act var count = carServices.GetAllCarsForUserWithId(firstUser.Id).Count(); var expectedCount = 2; var actualCount = count; // Assert Assert.Equal(expected: expectedCount, actual: actualCount); }
public void TestGetAllCarsForUserWithId_WithoutCarsForThisUser_ShouldReturnZeroCarsForTheUserWithIdNull() { // Arrange var contextFactory = new ApplicationDbContextFactory(); var context = contextFactory.CreateApplicationDbContext(); var mapperFactory = new AutoMapperFactory(); var mapper = mapperFactory.CreateMapper(); var carServices = new CarServices(context, mapper); SeedDbWithUsers(context); string userId = context.Users.FirstOrDefault().Id; // Act var count = carServices.GetAllCarsForUserWithId(userId).Count(); var expectedCount = 0; var actualCount = count; // Assert Assert.Equal(expected: expectedCount, actual: actualCount); }