public async Task GetAll_ReturnsAllElephants() { // arrange var totalElephantsLength = 2; var mockElephantRepo = new Mock <IElephantRepo>(); mockElephantRepo.Setup(x => x.GetAll()).ReturnsAsync( new List <Elephant>() { new Elephant() { name = "Bob" }, new Elephant() { name = "Billy" } }); ElephantService _tests = new ElephantService(mockElephantRepo.Object); // act var result = await _tests.GetAll(); // assert Assert.Equal(totalElephantsLength, result.Count); mockElephantRepo.VerifyAll(); }
public async Task GetElephants_ReturnsInvalidString() { // arrange var service = new ElephantService(_mapperMock.Object); // act var ex = await Assert.ThrowsAsync <FileNotFoundException>(() => service.GetElephants("fake")); // assert Assert.Equal("Could not find file 'C:\\Users\\sam.ballard\\source\\repos\\MovieWebApplication\\MovieIntegrationTests\\bin\\Debug\\netcoreapp3.1\\fake'.", ex.Message); }
public async Task GetElephants_Returns() { // arrange var service = new ElephantService(_mapperMock.Object); // act var elephants = await service.GetElephants(FILEPATH_TEST); // assert Assert.NotNull(elephants); Assert.IsType <List <Elephant> >(elephants); Assert.True(elephants.Count == 25); }
public async Task Get_ReturnsNullWhenIdIsNotFound() { var inputId = "67890"; Elephant elephantResult = null; var mockElephantRepo = new Mock <IElephantRepo>(); mockElephantRepo.Setup(x => x.Get(inputId)).ReturnsAsync( elephantResult ); ElephantService _tests = new ElephantService(mockElephantRepo.Object); var result = await _tests.Get(inputId); Assert.Null(result); mockElephantRepo.VerifyAll(); }
public async Task Get_ReturnsElephantById() { var expectedId = "12345"; var mockElephantRepo = new Mock <IElephantRepo>(); mockElephantRepo.Setup(x => x.Get(expectedId)).ReturnsAsync( new Elephant() { id = "12345" } ); ElephantService _tests = new ElephantService(mockElephantRepo.Object); var result = await _tests.Get(expectedId); Assert.Equal(expectedId, result.id); mockElephantRepo.VerifyAll(); }
public async Task Post_ReturnsAddedElephantToListOfElephants() { var newElephant = new Elephant() { name = "Andrew" }; var returnedElephant = newElephant; returnedElephant.id = Guid.NewGuid().ToString(); var mockElephantRepo = new Mock <IElephantRepo>(); mockElephantRepo.Setup(x => x.Add(newElephant)).ReturnsAsync( returnedElephant ); ElephantService _tests = new ElephantService(mockElephantRepo.Object); var result = await _tests.Add(newElephant); Assert.Equal(newElephant.name, result.name); Assert.NotNull(result.id); }