public async Task BrandMethod() { // Arrange BrandsController controller = new BrandsController(); // Act Task result = controller.GetBrand() as Task; // Assert Assert.IsNotNull(result); }
public async Task GetBrand_Success() { var dbContext = _fixture.Context; dbContext.Brands.Add(new Brand { BrandName = "TestGetBrand" }); await dbContext.SaveChangesAsync(); var controller = new BrandsController(dbContext); var result = await controller.GetBrand(); var actionResult = Assert.IsType <ActionResult <IEnumerable <BrandVm> > >(result); Assert.NotEmpty(actionResult.Value); }
public async Task ValidateGetBrandById() { _dbContext.Brands.Add(new Brand { Id = 99, Name = "GOG.com" }); var controller = new BrandsController(_dbContext); var result = await controller.GetBrand(99); var actionResult = Assert.IsType <ActionResult <BrandVm> >(result); Assert.NotNull(result); Assert.NotNull(actionResult); Assert.Equal("GOG.com", result.Value.Name); Assert.True(99 == result.Value.Id); }
public async Task Test_GetBrand_ShouldReturnBrand() { //arrange var id = 1; var brand = new Brand { Name = "TestBrand" }; brandRepositoryMock.Setup(p => p.GetBrand(id)).Returns(Task.FromResult(brand)); //act var result = await subject.GetBrand(id); var OkActionResult = result as OkObjectResult; //assert Assert.IsInstanceOf <OkObjectResult>(OkActionResult); Assert.AreEqual(brand, OkActionResult.Value); }
public async Task DeleteBrand_Success() { var dbContext = _fixture.Context; Brand brand = new Brand { Name = "Test brand" }; await dbContext.Brands.AddAsync(brand); await dbContext.SaveChangesAsync(); var brandsController = new BrandsController(dbContext); // Act var result = await brandsController.DeleteBrand(brand.ID); // Assert var deleteAtActionResult = Assert.IsType <NoContentResult>(result.Result); await Assert.ThrowsAsync <Exception>(async() => { await brandsController.GetBrand(brand.ID); }); }
public async void QueryBrandIdX_ReturnsCorrectBrand(int id) { // Arrange var mockRepo = new Mock <IVehicleCatalogRepository>(); mockRepo.Setup(repo => repo.GetBrand(id)) .Returns(Task.FromResult <Brand>(new Brand() { Id = id, Name = $"Brand {id}" })); 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.GetBrand(id); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <BrandForDetail>(okResult.Value); var topBrand = returnValue.name; Assert.Equal($"Brand {id}", topBrand); }
public async Task GetBrand_ShouldReturnNotEqual() { var brand = await brandsController.GetBrand(1); Assert.AreNotEqual("BMV", brand.Value.Name); }