コード例 #1
0
        public async Task UpdateClientsByIDSuccess()
        {
            var targetID = Guid.NewGuid();

            var options = new DbContextOptionsBuilder <DbndContext>()
                          .UseInMemoryDatabase(databaseName: "Dbnd5")
                          .Options;

            using (var context = new DbndContext(options))
            {
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client()
                {
                    UserName = "******", Email = "*****@*****.**", ClientID = targetID
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.UpdateClientByIDAsync(targetID, new Logic.Objects.Client()
                {
                    UserName = "******"
                });

                var client = repository.GetClientByIDAsync(targetID).Result;
                Assert.Equal("Abagail", client.UserName);
            }
        }
コード例 #2
0
        public void GetClientWithInvalidEmail(string email)
        {
            var options = new DbContextOptionsBuilder <DbndContext>()
                          .UseInMemoryDatabase(databaseName: "Dbnd2")
                          .Options;

            using (var context = new DbndContext(options))
            {
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.SaveChanges();

                Repository repository = new Repository(context);

                var client = repository.GetClientByEmailAsync(email).Result;
                Assert.Null(client);
            }
        }
コード例 #3
0
        public async Task DeleteCharacterAsyncSuccessful()
        {
            var targetID = Guid.NewGuid();
            var options  = new DbContextOptionsBuilder <DbndContext>()
                           .UseInMemoryDatabase(databaseName: "Dbnd21")
                           .Options;

            using (var context = new DbndContext(options))
            {
                context.Character.Add(new Character {
                    CharacterID = targetID, FirstName = "Rowan", LastName = "Garrowsson", ClientID = Guid.NewGuid()
                });
                context.Character.Add(new Character {
                    FirstName = "Brom", LastName = "Irons", ClientID = Guid.NewGuid()
                });
                context.Character.Add(new Character {
                    FirstName = "Orik", LastName = "Slayersfelt", ClientID = Guid.NewGuid()
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.DeleteCharacterByIDAsync(targetID);

                var characters      = context.Character;
                var charactersCount = characters.Count();

                Assert.Equal(2, charactersCount);
            }
        }
コード例 #4
0
        public async Task UpdateCharacterAsyncSuccessful()
        {
            var targetID = Guid.NewGuid();
            var options  = new DbContextOptionsBuilder <DbndContext>()
                           .UseInMemoryDatabase(databaseName: "Dbnd20")
                           .Options;

            using (var context = new DbndContext(options))
            {
                context.Character.Add(new Character {
                    CharacterID = targetID, FirstName = "Rowan", LastName = "Garrowsson", ClientID = Guid.NewGuid()
                });
                context.Character.Add(new Character {
                    FirstName = "Brom", LastName = "Irons", ClientID = Guid.NewGuid()
                });
                context.Character.Add(new Character {
                    FirstName = "Orik", LastName = "Slayersfelt", ClientID = Guid.NewGuid()
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.UpdateCharacterByIDAsync(targetID, new Logic.Objects.Character()
                {
                    FirstName = "Robin"
                });

                var character     = context.Character.FirstAsync(x => x.CharacterID == targetID).Result;
                var characterName = character.FirstName;

                Assert.Equal("Robin", characterName);
            }
        }
コード例 #5
0
        public async Task DeleteGameAsyncSuccess()
        {
            var targetID = Guid.NewGuid();
            var options  = new DbContextOptionsBuilder <DbndContext>()
                           .UseInMemoryDatabase(databaseName: "Dbnd16")
                           .Options;

            using (var context = new DbndContext(options))
            {
                context.Game.Add(new Game {
                    GameID = targetID, ClientID = Guid.NewGuid(), GameName = "DragonBreath"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "LionWhisper"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "HorseTooth"
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.DeleteGameByIDAsync(targetID);

                var games = context.Game;
                var count = games.Count();
                Assert.Equal(2, count);
            }
        }
コード例 #6
0
        public async Task UpdateGameAsyncSuccess()
        {
            var targetID = Guid.NewGuid();
            var options  = new DbContextOptionsBuilder <DbndContext>()
                           .UseInMemoryDatabase(databaseName: "Dbnd15")
                           .Options;

            using (var context = new DbndContext(options))
            {
                context.Game.Add(new Game {
                    GameID = targetID, ClientID = Guid.NewGuid(), GameName = "DragonBreath"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "LionWhisper"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "HorseTooth"
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.UpdateGameAsync(targetID, new Logic.Objects.Game()
                {
                    GameName = "HippoEars"
                });

                var game       = context.Game.FirstAsync(x => x.GameID == targetID).Result;
                var targetName = game.GameName;
                Assert.Equal("HippoEars", targetName);
            }
        }
コード例 #7
0
        public void GetGameByGameIDAsyncSuccess()
        {
            var targetID = Guid.NewGuid();
            var options  = new DbContextOptionsBuilder <DbndContext>()
                           .UseInMemoryDatabase(databaseName: "Dbnd12")
                           .Options;

            using (var context = new DbndContext(options))
            {
                context.Game.Add(new Game {
                    GameID = targetID, ClientID = Guid.NewGuid(), GameName = "DragonBreath"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "LionWhisper"
                });
                context.Game.Add(new Game {
                    GameID = Guid.NewGuid(), ClientID = Guid.NewGuid(), GameName = "HorseTooth"
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                var        game       = repository.GetGameByIDAsync(targetID).Result;
                Assert.Equal(targetID, game.GameID);
            }
        }
コード例 #8
0
        public async Task DeleteClientsByIDSuccess()
        {
            var targetID = Guid.NewGuid();

            var options = new DbContextOptionsBuilder <DbndContext>()
                          .UseInMemoryDatabase(databaseName: "Dbnd6")
                          .Options;

            using (var context = new DbndContext(options))
            {
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client {
                    UserName = "******", Email = "*****@*****.**"
                });
                context.Client.Add(new Client()
                {
                    UserName = "******", Email = "*****@*****.**", ClientID = targetID
                });
                context.SaveChanges();
            }

            using (var context = new DbndContext(options))
            {
                Repository repository = new Repository(context);
                await repository.DeleteClientByIDAsync(targetID);

                var clients = await context.Client.ToListAsync();

                var clientCount = clients.Count();
                Assert.Equal(2, clientCount);
            }
        }
コード例 #9
0
ファイル: Repository.cs プロジェクト: kmanrulze/ksj-project2
 public Repository(DbndContext dbContext)
 {
     _context = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }