public void Register_Should_Throw_When_Add_Non_Existent_FK( Guid microsserviceId, int LevelId, int environmentId) { // Arrange var context = GenerateContext("RegisterBadError"); var service = new ErrorService(context); Error entry = new Error { Id = 1, Title = "Teste1", Origin = "1.0.0.1", Details = "Detail1", ErrorDate = DateTime.Today, MicrosserviceClientId = microsserviceId, EnviromentId = environmentId, LevelId = LevelId, IsArchived = false }; // Act // Assert Assert.Throws <Exception>(() => service.Register(entry)); }
public void Register_Should_Add_New_Error() { // Arrange var fakeContext = new FakeContext("RegisterError"); fakeContext.FillWith <Level>(); fakeContext.FillWith <Microsservice>(); fakeContext.FillWith <Model.Models.Environment>(); var context = new CentralDeErrosDbContext(fakeContext.FakeOptions); var service = new ErrorService(context); Error entry = new Error { Title = "Teste1", Origin = "1.0.0.1", Details = "Detail1", ErrorDate = DateTime.Today, MicrosserviceClientId = new Guid("031c156c-c072-4793-a542-4d20840b8031"), EnviromentId = 1, LevelId = 1, IsArchived = false }; // Act var result = service.Register(entry); // Assert Assert.True(result.Id == 1, $"Should return new error with id 1. returned: {result.Id}"); Assert.True(context.Errors.Count() == 1, $"Should have one error saved. > Amount: {context.Errors.Count()}"); }