public void FourPlusFiveEqualsNine() { // arrange //creating the in-memory Db var options = new DbContextOptionsBuilder <RpsDbContext>() .UseInMemoryDatabase(databaseName: "TestDb") .Options; int z; // act // add to the In-Memory Db using (var context = new RpsDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); int x = 4; int y = 5; z = x + y; context.SaveChanges(); } //assert // verify the the result was as expected using (var context = new RpsDbContext(options)) { Assert.Equal(9, z); } }
public void CreatePlayerAndAddsToDatabase() { //arrange //creating the in-memory Db var options = new DbContextOptionsBuilder <RpsDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; //act //add to the in-memory db Player p1 = new Player(); string fName = "Sparky"; string lName = "Jones"; using (var context = new RpsDbContext(options)){ context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); p1 = repo.CreatePlayer(fName, lName); context.SaveChanges(); } //assert //verify the result was as expected using (var context = new RpsDbContext(options)){ RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); // Player result = context.players.Where(x => x.Fname == fName && x.Lname == lName).FirstOrDefault(); Player result = repo.CreatePlayer("Sparky", "Jones"); Assert.True(p1.playerId.Equals(result.playerId)); } }
public void CreatePlaterSavesANewPlayerToTheDb() { // arrange // creating the in memory database var options = new DbContextOptionsBuilder <RpsDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; // act // add to the In-Memory Db Player p1 = new Player(); using (var context = new RpsDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); p1 = repo.CreatePlayer("Sparky", "Jones"); context.SaveChanges(); } // assert // verify the result was as expected using (var context = new RpsDbContext(options)) { RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); Player result = repo.CreatePlayer("Sparky", "Jones"); // Assert.Equal(p1.PlayerId, result.PlayerId); Assert.True(p1.PlayerId.Equals(result.PlayerId)); } }
public void Test1() { //arrange //creating the in-memory Db var options = new DbContextOptionsBuilder <RpsDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; //act //add to the in-memory db using (var context = new RpsDbContext(options)){ context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); context.SaveChanges(); } //assert //verify the result was as expected using (var context = new RpsDbContext(options)){ RpsGameRepositoryLayer repo = new RpsGameRepositoryLayer(context); } }