Exemplo n.º 1
0
        public static void RenameDeck(string deckName, string newName)
        {
            var deck = DeckRepository.GetDeck(deckName);

            deck.DeckName = newName;
            DeckRepository.UpdateDeckName(deck);
        }
        public void UserCanChangePassword()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var cardRepository = new CardRepository(Session);
            var deckRepository = new DeckRepository(Session);

            var card = new Card("A", "B", "C", CardRarity.Special, "D", "E");
            var deck = new Deck("F");
            var user = new User("*****@*****.**", "Appie", userRepository);

            deck.Cards.Add(card);
            deck.Cards.Add(card);
            user.Decks.Add(deck);
            user.Cards.Add(card);

            Session.BeginTransaction();

            userRepository.CreateNewUser(user, "test123");
            cardRepository.Save(card);
            deckRepository.Save(deck);

            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Evict(user);
            Session.Clear();

            var userFromRepository = userRepository.Get(user.Id);

            var message = userRepository.ChangePassword(userFromRepository.Email, "test123", "etende", "etende");

            Assert.AreEqual(message, ChangePassswordMessage.PasswordChanged);
        }
        public GamesController()
        {
            SolveOrDrinkItEntities db = new SolveOrDrinkItEntities();

            repo     = new GameRepository(db);
            deckRepo = new DeckRepository(db);
        }
        public DecksController()
        {
            SolveOrDrinkItEntities db = new SolveOrDrinkItEntities();

            repo     = new DeckRepository(db);
            taskRepo = new TaskRepository(db);
        }
Exemplo n.º 5
0
        public static bool OutputDeckToFile(string deckName, string path)
        {
            var deck = DeckRepository.GetDeck(deckName);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            var temp = File.Create(path);

            temp.Flush();
            temp.Close();

            using (var file = new StreamWriter(@path))
            {
                file.WriteLine($"1x {deck.Commander.Name} *CMDR*");

                foreach (var card in deck.Cards)
                {
                    file.WriteLine($"1x {card.Name}");
                }

                file.Close();
            }

            return(true);
        }
Exemplo n.º 6
0
        public void Test_CardsInDeckRepo(string suit, int value)
        {
            DeckRepository dr    = new DeckRepository(1);
            var            cards = dr.GetDeck().Cards;

            Assert.True(cards.Exists(x => x.Suit == suit && x.Value == value));
        }
Exemplo n.º 7
0
        public void GetDecks_WhenNoDecksFound_ReturnsEmptySet()
        {
            var hashidsMock    = new Mock <IHashids>();
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);
            var decks          = deckRepository.GetDecks();

            Assert.IsEmpty(decks);
        }
Exemplo n.º 8
0
        public void Update_WhenDeckNotFound_Throws()
        {
            var deckHash       = "deckHash";
            var hashidsMock    = new Mock <IHashids>();
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);

            Assert.Throws <DeckNotFoundException>(() => deckRepository.Update(deckRepository.GetDeck(deckHash)));
        }
Exemplo n.º 9
0
        public void Initialize()
        {
            Cards = new List <DCard>();
            DeckRepository dr = new DeckRepository(1);

            Cards = dr.GetDeck().Cards;
            Shuffle();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="context">Context to use</param>
 public UnitOfWork(BJDBContext context)
 {
     _context = context;
     Cards    = new CardRepository(_context);
     Decks    = new DeckRepository(_context);
     Games    = new GameRepository(_context);
     Players  = new PlayerRepository(_context);
 }
Exemplo n.º 11
0
 public void Setup()
 {
     _publicApi      = new Mock <IPublicApi>(MockBehavior.Strict);
     _deckBuilder    = new Mock <IDestinyDeckBuilder>(MockBehavior.Strict);
     _deckListId     = "1";
     _deck           = TestUtils.GetValidDestinyDeck();
     _deckList       = new DeckList();
     _deckRepository = new DeckRepository(_publicApi.Object, _deckBuilder.Object);
 }
Exemplo n.º 12
0
        public void Insert_InsertsGivenDeck()
        {
            var hashidsMock    = new Mock <IHashids>();
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);

            Assert.That(deckRepository.GetDecks().Count() == 0);
            deckRepository.Insert(new Deck {
            });
            Assert.That(deckRepository.GetDecks().Count() == 1);
        }
Exemplo n.º 13
0
        public void Insert_AssignsHash()
        {
            var hashidsMock    = new Mock <IHashids>();
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);
            var deckToInsert   = new Deck();

            deckRepository.Insert(deckToInsert);

            hashidsMock.Verify(x => x.Encode(It.IsAny <int>()), Times.Once());
        }
Exemplo n.º 14
0
        public void GetDecks_WhenDecksFound_ReturnsAll()
        {
            var hashidsMock    = new Mock <IHashids>();
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);

            deckRepository.Insert(new Deck {
            });
            var decks = deckRepository.GetDecks();

            Assert.AreEqual(decks.Count(), 1);
        }
Exemplo n.º 15
0
        public static IEnumerable <CardVm> GetDeckLands(string deckName)
        {
            Console.WriteLine("Getting Deck");
            var deck = DeckRepository.GetDeck(deckName);

            Console.WriteLine("Looking for legal cards");
            var legalCards = CardRepository.GetAllCommanderLegalCardInGivenColors(CardBLL.GetCardColors(CardMapper.Map(deck.Commander)));

            Console.WriteLine($"Attempting to find lands in {legalCards.Count()} cards.");

            return(CardMapper.Map(legalCards.Where(c => c.Types.Contains("land"))));
        }
Exemplo n.º 16
0
        public void Remove_WhenDeckFound_RemovesIt()
        {
            var deckHash    = "deckHash";
            var hashidsMock = new Mock <IHashids>();

            hashidsMock.Setup(x => x.Encode(It.IsAny <int>())).Returns(deckHash);
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);

            deckRepository.Insert(new Deck {
            });
            deckRepository.Remove(deckHash);

            Assert.That(deckRepository.GetDecks().Count() == 0);
        }
        public async Task DeleteAsyncDeckAsync_Should_ReturnOk()
        {
            // Arrange
            var dbContext = InMemoryDbContext.CreateDbContext();
            var deck      = _fixture.Create <DeckEntity>();
            var expectedNumberOfDeletion = 1 + deck.Cards.Count;

            dbContext.Add(deck);
            dbContext.SaveChanges();

            // Act
            var deckRepository = new DeckRepository(dbContext);
            var result         = await deckRepository.DeleteAsync(deck.DeckId);

            // Assert
            Assert.AreEqual(result, expectedNumberOfDeletion);
        }
Exemplo n.º 18
0
        public void Update_WhenDeckFound_Updates()
        {
            var deckHash    = "deckHash";
            var hashidsMock = new Mock <IHashids>();

            hashidsMock.Setup(x => x.Encode(It.IsAny <int>())).Returns(deckHash);
            var deckRepository = new DeckRepository(DbContextFactory.Create(), hashidsMock.Object);

            deckRepository.Insert(new Deck());

            var deck = deckRepository.GetDeck(deckHash);

            deck.Remaining = 21;
            deckRepository.Update(deck);

            Assert.That(deckRepository.GetDeck(deckHash).Remaining == 21);
        }
Exemplo n.º 19
0
        public static DeckStatsVm GetDeckStats(string deckName)
        {
            var deck = DeckRepository.GetDeck(deckName);

            var deckStats = new DeckStatsVm
            {
                DeckName          = deck.DeckName,
                CreatureCount     = deck.Cards.Count(c => c.Types.Contains("creature")) + 1,
                LandCount         = deck.Cards.Count(c => c.Types.Contains("land")),
                ArtifactCount     = deck.Cards.Count(c => c.Types.Contains("artifact")),
                SorceryCount      = deck.Cards.Count(c => c.Types.Contains("sorcery")),
                InstantCount      = deck.Cards.Count(c => c.Types.Contains("instant")),
                PlaneswalkerCount = deck.Cards.Count(c => c.Types.Contains("planeswalker")),
                EnchantmentCount  = deck.Cards.Count(c => c.Types.Contains("enchantment"))
            };

            return(deckStats);
        }
Exemplo n.º 20
0
 public UnitOfWork(MemoContext context)
 {
     this.dbContext = new MemoContext();
     Answers        = new AnswerRepository(dbContext);
     Cards          = new CardRepository(dbContext);
     CardTypes      = new CardTypeRepository(dbContext);
     Categories     = new CategoryRepository(dbContext);
     Comments       = new CommentRepository(dbContext);
     Course         = new CourseRepository(dbContext);
     DeckCourses    = new DeckCourseRepository(dbContext);
     Decks          = new DeckRepository(dbContext);
     Reports        = new ReportRepository(dbContext);
     Roles          = new RoleRepository(dbContext);
     Statistics     = new StatisticRepository(dbContext);
     UserCourses    = new UserCourseRepository(dbContext);
     Users          = new UserRepository(dbContext);
     UserRoles      = new UserRoleRepository(dbContext);
 }
Exemplo n.º 21
0
        public static bool CreateDeck(string deckName, string commanderName)
        {
            var commander = CardRepository.GetCardByName(commanderName);

            if (commander == null)
            {
                return(false);
            }

            var deck = new DeckDm
            {
                Id        = 0,
                DeckName  = deckName,
                Commander = commander
            };

            DeckRepository.InsertDeck(deck);

            return(true);
        }
Exemplo n.º 22
0
        public void CanCreateDeck()
        {
            var deckRepository = new DeckRepository(Session);
            var cardRepository = new CardRepository(Session);
            var card           = new Card("A", "type", "m14", CardRarity.Special, "Barry", "nowhere");
            var deck           = new Deck("DeckName");

            deck.Cards.Add(card);

            Session.BeginTransaction();
            cardRepository.Save(card);
            deckRepository.Save(deck);
            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Clear();

            var deckFromRepository = deckRepository.Get(deck.Id);

            Assert.AreEqual("DeckName", deckFromRepository.Name);
            Assert.AreEqual(1, deckFromRepository.Cards.Count);
        }
Exemplo n.º 23
0
        public static bool BuildCommanderDeck(string deckName, string tribeType)
        {
            var deck = DeckRepository.GetDeck(deckName);

            if (deck.Commander == null)
            {
                return(false);
            }

            var legalCards = CardRepository.GetAllCommanderLegalCardInGivenColors(CardBLL.GetCardColors(CardMapper.Map(deck.Commander)));
            var tempCards  = legalCards.Where(c => c.SubTypes.Contains(tribeType) || c.RulesText.Contains(tribeType) && c.Id != deck.Commander.Id);

            if (tempCards.Count() > 34)
            {
                tempCards = tempCards.ToList().GetRange(0, 34);
            }



            DeckRepository.UpdateDeck(deck);

            return(true);
        }
        public void CanAddDeckToMultipleUsers()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var deckRepository = new DeckRepository(Session);

            var deck = new Deck("DeckName");

            var user1 = new User("*****@*****.**", "Robin van der Knaap", userRepository);

            user1.Decks.Add(deck);

            var user2 = new User("*****@*****.**", "Erwin Bonnet", userRepository);

            user2.Decks.Add(deck);

            Session.BeginTransaction();

            deckRepository.Save(deck);

            userRepository.CreateNewUser(user1, "test123");
            userRepository.CreateNewUser(user2, "test123");

            Session.Transaction.Commit();

            Session.Evict(deck);
            Session.Evict(user1);
            Session.Evict(user2);
            Session.Clear();

            var userFromDatabase1 = userRepository.Get(user1.Id);
            var userFromDatabase2 = userRepository.Get(user2.Id);

            Assert.AreEqual(1, userFromDatabase1.Decks.Count);
            Assert.AreEqual(1, userFromDatabase2.Decks.Count);
            Assert.AreEqual(deck, userFromDatabase1.Decks.First());
            Assert.AreEqual(deck, userFromDatabase2.Decks.First());
        }
        public void CanRegisterUser()
        {
            var userRepository = new UserRepository(Session, Encryptor);
            var cardRepository = new CardRepository(Session);
            var deckRepository = new DeckRepository(Session);

            var card = new Card("A", "B", "C", CardRarity.Special, "D", "E");
            var deck = new Deck("F");
            var user = new User("*****@*****.**", "Appie", userRepository);

            deck.Cards.Add(card);
            deck.Cards.Add(card);
            user.Decks.Add(deck);
            user.Cards.Add(card);

            Session.BeginTransaction();

            userRepository.CreateNewUser(user, "test123");
            cardRepository.Save(card);
            deckRepository.Save(deck);

            Session.Transaction.Commit();

            Session.Evict(card);
            Session.Evict(deck);
            Session.Evict(user);
            Session.Clear();

            var userFromRepository = userRepository.Get(user.Id);

            Assert.AreEqual(user.DisplayName, userFromRepository.DisplayName);
            Assert.AreEqual(userFromRepository.Decks[0].Cards.Count, deck.Cards.Count);
            Assert.AreEqual(userFromRepository.Cards.Count, 1);
            Assert.AreEqual(userRepository.AuthenticateUser(userFromRepository.Email, "test123"), AuthenticateMessages.AuthenticationSuccessfull);
            Assert.AreEqual(userRepository.AuthenticateUser("*****@*****.**", "blaat"), AuthenticateMessages.UsernameDoesNotExist);
            Assert.AreEqual(userRepository.AuthenticateUser(userFromRepository.Email, "tester"), AuthenticateMessages.WrongEmailOrPassword);
        }
        public async Task GetByDeckByIdWithCardsAsync_Should_ReturnDeckInfo()
        {
            // Arrange
            var dbContext = InMemoryDbContext.CreateDbContext();
            var deck      = _fixture.Create <DeckEntity>();

            dbContext.Add(deck);
            dbContext.SaveChanges();

            // Act
            var deckRepository = new DeckRepository(dbContext);
            await deckRepository.GetByIdAsync(deck.DeckId);

            // Assert
            var result = dbContext.Find <DeckEntity>(deck.DeckId);

            result
            .Should()
            .NotBeNull();

            result
            .Should()
            .BeEquivalentTo(deck);
        }
Exemplo n.º 27
0
 public static void RemoveCardFromDeck(string deckName, string cardName)
 {
     DeckRepository.RemoveCardFromDeck(deckName, cardName);
 }
Exemplo n.º 28
0
 public DeckController(DeckRepository repository, IConfiguration configuration)
 {
     _repository    = repository;
     _configuration = configuration;
 }
Exemplo n.º 29
0
 public static void DeleteDeck(string deckName)
 {
     DeckRepository.Delete(deckName);
 }
Exemplo n.º 30
0
 public DeckService()
 {
     _deckRepository = SingletonFactory.GetObject <DeckRepository>();
 }