public async Task TestGetAccessorieById_WithNoneExistingAccessorieId_ShouldReturnNull() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedAccessorieAsync(context); AutoMapperConfig.RegisterMappings(typeof(DetailsAccessorieViewModel).Assembly); // Act and Assert Assert.Throws <ArgumentNullException>(() => accessorieService.GetById <DetailsAccessorieViewModel>("Тестово id")); }
public async Task TestGetAccessorieById_WithExistingAccessorieId_ShouldReturnAccessorie() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedAccessorieAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DetailsAccessorieViewModel).Assembly); var expected = context.Accessories.SingleOrDefault(accessorie => accessorie.Id == "abc1"); var actualResult = accessorieService.GetById <DetailsAccessorieViewModel>("abc1"); // Assert AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetAccessorie with name, returns name")); AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetAccessorie with name, returns description")); AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetAccessorie with name, returns ImagePath")); }