public void GetBrands_ShouldReturnAllBrandAsync() { var brands = brandsController.GetBrands().Value; var actualList = GetTestBrand(); Assert.AreEqual(brands.ToString(), actualList.ToString()); }
public async void QueryBrandList_ReturnsBrandsAscendingByName() { // Arrange var mockRepo = new Mock <IVehicleCatalogRepository>(); mockRepo.Setup(repo => repo.GetBrands()) .Returns(Task.FromResult <IEnumerable <Brand> >(new List <Brand>() { new Brand() { Id = 1, Name = "Crand 1" }, new Brand() { Id = 2, Name = "Brand 2" }, new Brand() { Id = 3, Name = "Drand 3" }, }.OrderBy(o => o.Name))); var mapper = _dependencyFixture.ServiceProvider.GetService <IMapper>(); var logger = Mock.Of <ILogger <BrandsController> >(); var controller = new BrandsController(mockRepo.Object, mapper, logger); // Act var result = await controller.GetBrands(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <BrandForList> >(okResult.Value); var topBrand = returnValue.FirstOrDefault().name; Assert.Equal("Brand 2", topBrand); }
public async Task GetCategory_Success() { _applicationDbContex.Brands.Add(new Brand { Name = "Test category" }); await _applicationDbContex.SaveChangesAsync(); var controller = new BrandsController(_applicationDbContex); var result = await controller.GetBrands(); var actionResult = Assert.IsType <ActionResult <IEnumerable <BrandVm> > >(result); Assert.NotEmpty(actionResult.Value); }
public async Task GetBrand_Success() { var dbContext = _fixture.Context; await dbContext.Brands.AddRangeAsync(new Brand { Name = "Test1 brand" }, new Brand { Name = "Test2 brand" }, new Brand { Name = "Test3 brand" }); await dbContext.SaveChangesAsync(); var brandService = new BrandService(dbContext); var brandsController = new BrandsController(brandService); var result = await brandsController.GetBrands(); var actionResult = Assert.IsType <OkObjectResult>(result.Result); Assert.NotEmpty(actionResult.Value as IEnumerable <BrandVm>); }
public async Task GetBrand_Success() { var dbContext = _fixture.Context; dbContext.Brands.Add(new Brand { Name = "Test brand" }); await dbContext.SaveChangesAsync(); var controller = new BrandsController(dbContext); var result = await controller.GetBrands(); var actionResult = Assert.IsType <ActionResult <IEnumerable <BrandVm> > >(result); Assert.NotEmpty(actionResult.Value); }
public async Task ValidateGetBrands() { _dbContext.Brands.Add(new Brand { Id = 99, Name = "GOG.com" }); await _dbContext.SaveChangesAsync(); var controller = new BrandsController(_dbContext); var result = await controller.GetBrands(); var actionResult = Assert.IsType <ActionResult <IEnumerable <BrandVm> > >(result); Assert.NotEmpty(actionResult.Value); }
public async Task GetBrands_ShouldOKObjects() { //Arrange var brands = new List <Brand>() { new Brand { Id = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"), Name = "Brand1" }, new Brand { Id = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"), Name = "Brand2" } }; var mock = new Mock <MSProductsDB>(MockBehavior.Strict); mock.Setup(repo => repo.Brands.AddRange(brands)); var brandCTRL = new BrandsController(mock.Object); //ACt var result = brandCTRL.GetBrands(); //Assert Assert.IsNotNull(result); var objResult = result as ActionResult <IEnumerable <Brand> >; Assert.IsNotNull(objResult); var resultData = objResult.Value as IEnumerable <Brand>; Assert.IsNotNull(resultData); var resultList = resultData.ToList(); Assert.AreEqual(brands.Count, resultList.Count); for (int i = 0; i < brands.Count; i++) { Assert.AreEqual(brands[i].Id, resultList[i].Id); Assert.AreEqual(brands[i].Name, resultList[i].Name); } }
public async Task Test_GetBrands_ShouldReturnListOfBrands() { //arrange var brands = new List <Brand> { new Brand { Name = "TestBrand" } }; brandRepositoryMock.Setup(p => p.GetBrands()).Returns(Task.FromResult(brands)); //act var result = await subject.GetBrands(); var OkActionResult = result as OkObjectResult; //assert Assert.IsInstanceOf <OkObjectResult>(OkActionResult); Assert.AreEqual(brands, OkActionResult.Value); }