public async void PostDatacenter() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; await using var context = new ApplicationDbContext(options); IDatacenterRepository repository = new DatacenterRepository <ApplicationDbContext>(context); IDatacenterService service = new DatacenterService(repository, AuditMock.Object, _mapper); IApiErrorResources error = new ApiErrorResources(); var controller = new DatacentersController(service, error, _mapper); //checking to see if post works var createDatacenterApiDto = GenerateCreateDatacenterApiDto(); var sign = await controller.Post(createDatacenterApiDto); var result = await context.Datacenters.FirstOrDefaultAsync(); // weak assertion. TODO: assert property-for-property equality Assert.NotNull(result); //checking to see if get works var id = Guid.NewGuid(); var datacenter = GenerateDatacenter(id); await context.Datacenters.AddAsync(datacenter); var numAdded = await context.SaveChangesAsync(); var getDatacenter = await controller.Get(datacenter.Id); // weak assertion. TODO: assert property-for-property equality Assert.NotNull(getDatacenter.Result); }
public async Task ReadNode_ByName(string name) { var dbContext = DbContextTestHelper.GetDbContext(); fixture.AddSeed(dbContext); var repository = new DatacenterRepository(dbContext); var node = await repository.ReadAsync(c => c.Name == name); Assert.NotNull(node); }
public async Task ReadAllNodes() { var dbContext = DbContextTestHelper.GetDbContext(); fixture.AddSeed(dbContext); var repository = new DatacenterRepository(dbContext); var nodes = await repository.ReadsAsync(); Assert.Equal(4, nodes.Count()); }
public async Task InsertNode_WithNameAndCpu(string name, int cpu) { var dbContext = DbContextTestHelper.GetDbContext(); fixture.AddSeed(dbContext); var repository = new DatacenterRepository(dbContext); var inserted = await repository.InsertAsync(new DatacenterNode() { Name = name, Core = cpu }); Assert.Equal(1, inserted); }
public async Task UpdateNode_ByName_UpdateRam(string name, int ram) { var dbContext = DbContextTestHelper.GetDbContext(); fixture.AddSeed(dbContext); var repository = new DatacenterRepository(dbContext); var node = await repository.ReadAsync(c => c.Name == name); Assert.NotNull(node); node.RamTotal = ram; var updated = await repository.UpdateAsync(node); Assert.Equal(1, updated); }