public void Dispose() { if (Context != null) { Context = null; } }
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()}"); }
public FakeContext(string testName) { FakeOptions = new DbContextOptionsBuilder <CentralDeErrosDbContext>() .UseInMemoryDatabase(databaseName: $"CentralDeErrors_{testName}") .Options; context = new CentralDeErrosDbContext(FakeOptions); DataFileNames.Add(typeof(Model.Models.Environment), $"FakeData{Path.DirectorySeparatorChar}environment.json"); DataFileNames.Add(typeof(Error), $"FakeData{Path.DirectorySeparatorChar}error.json"); DataFileNames.Add(typeof(Level), $"FakeData{Path.DirectorySeparatorChar}level.json"); DataFileNames.Add(typeof(Microsservice), $"FakeData{Path.DirectorySeparatorChar}microsservice.json"); }
public void FillWith <T>() where T : class { using (var context = new CentralDeErrosDbContext(FakeOptions)) { if (context.Set <T>().Count() == 0) { foreach (T item in GetFakeData <T>()) { context.Set <T>().Add(item); } context.SaveChanges(); } } }
public void Delete_Should_Remove_The_Right_Environment() { // Arrange using var fakeContext = new FakeContext("deleteEnvironment"); fakeContext.FillWith <Model.Models.Environment>(); var context = new CentralDeErrosDbContext(fakeContext.FakeOptions); var service = new EnvironmentService(context); // Act service.Delete(1); // Assert Assert.Null(context.Environments.Find(1)); }
public EnvironmentService(CentralDeErrosDbContext context) : base(context) { }
public CentralDeErrosDbContext GenerateEmptyContext() { context = new CentralDeErrosDbContext(FakeOptions); return(context); }
public CentralDeErrosDbContext GenerateContext() { FillWithAll(); context = new CentralDeErrosDbContext(FakeOptions); return(context); }
public MicrosserviceService(CentralDeErrosDbContext context) : base(context) { }
public LevelService(CentralDeErrosDbContext context) : base(context) { }
public ErrorService(CentralDeErrosDbContext context) : base(context) { }
public ServiceBase(CentralDeErrosDbContext context) { Context = context; Context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }