public void Should_Be_Not_Found_When_Get_By_Id(int id) { var fakeContext = new FakeContext(); fakeContext.FillWith <SystemModel>(); using (ApplicationDbContext dbContext = new ApplicationDbContext(fakeContext.FakeOptions)) { var service = new SystemService(dbContext); var controller = new SystemController(service); var result = controller.Get(id); Assert.IsType <NotFoundObjectResult>(result.Result); result.Value.Should().BeNull(); } }
public void Should_Be_Ok_When_Get_By_Id(int id) { var fakeContext = new FakeContext(); fakeContext.FillWith <SystemModel>(); using (ApplicationDbContext dbContext = new ApplicationDbContext(fakeContext.FakeOptions)) { var service = new SystemService(dbContext); var controller = new SystemController(service); var result = controller.Get(id); var expected = service.Get(s => s.Id == id).FirstOrDefault(); Assert.IsType <OkObjectResult>(result.Result); result = (result.Result as OkObjectResult).Value as SystemModel; result.Value.Should().BeSameAs(expected); } }
public void Should_Be_Ok_When_GetAll() { var fakeContext = new FakeContext(); fakeContext.FillWith <SystemModel>(); using (ApplicationDbContext dbContext = new ApplicationDbContext(fakeContext.FakeOptions)) { var service = new SystemService(dbContext); var controller = new SystemController(service); var result = controller.Get(); var expected = service.GetAll().ToList(); Assert.IsType <OkObjectResult>(result.Result); result = (result.Result as OkObjectResult).Value as List <SystemModel>; result.Value.Should().BeEquivalentTo(expected); } }