Esempio n. 1
0
        public void DeleteChallenge()
        {
            var repository = new TestRepository();

            // add test challenges
            var challenge1 = new Challenge() { Question = "Test Question 1" };
            var challenge2 = new Challenge() { Question = "Test Question 2" };
            repository.Add(challenge1);
            repository.Add(challenge2);

            // add answers
            var answer1a = new ChallengeAnswer() { Answer = "Test Answer 1a", Correct = true, ChallengeId = challenge1.Id };
            var answer1b = new ChallengeAnswer() { Answer = "Test Answer 1b", Correct = false, ChallengeId = challenge1.Id };
            var answer2a = new ChallengeAnswer() { Answer = "Test Answer 2a", Correct = true, ChallengeId = challenge2.Id };
            var answer2b = new ChallengeAnswer() { Answer = "Test Answer 2b", Correct = false, ChallengeId = challenge2.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1a, answer1b, answer2a, answer2b });

            // delete one challenge
            challenge1.Delete();

            // verify challenge and answers are deleted
            Assert.IsEmpty(repository.Find<Challenge>(x => x.Id == challenge1.Id));
            Assert.IsEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer1a.Id));
            Assert.IsEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer1b.Id));

            // verify other challenge is not deleted
            Assert.IsNotEmpty(repository.Find<Challenge>(x => x.Id == challenge2.Id));
            Assert.IsNotEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer2a.Id));
            Assert.IsNotEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer2b.Id));
        }
Esempio n. 2
0
        public void GetNextChallengeBoardCategory()
        {
            var repository = new TestRepository();

            // create a game with some challenges
            var board = new Board();
            repository.Add(board);
            var game = new Game() { BoardId = board.Id };
            repository.Add(game);
            var category = new ChallengeCategory();
            repository.Add(category);
            var challenge1 = new Challenge() { ChallengeCategoryId = category.Id };
            var challenge2 = new Challenge() { ChallengeCategoryId = category.Id };
            var challenge3 = new Challenge() { ChallengeCategoryId = category.Id };
            var challenges = new Challenge[] { challenge1, challenge2, challenge3 };
            repository.AddAll(challenges);
            repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category.Id });

            // keep getting the next challenge until all challenges should have been used
            var usedChallenges = new List<Challenge>();
            foreach (Challenge challenge in challenges)
            {
                usedChallenges.Add(game.GetNextChallenge(0));
            }

            // verify that all challenges were used
            CollectionAssert.AreEqual(challenges.Select(x => x.Id).OrderBy(x => x), usedChallenges.Select(x => x.Id).OrderBy(x => x));

            // verify that more challenges can be retrieved
            Assert.IsNotNull(game.GetNextChallenge(0));
        }
Esempio n. 3
0
        public void Repository_Count_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());
            repository.Add("Tester", new object());

            repository.Count.Should().Be(2);
        }
Esempio n. 4
0
        public void Repository_AddMatch_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());

            var result = repository.Add("Test", new object());

            result.Should().BeFalse();
        }
Esempio n. 5
0
        public void RepositoryValuesTest()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());
            repository.Add("Tester", new object());

            var valueList = new List <object>(repository.Values);

            valueList.Count.Should().Be(2);
        }
Esempio n. 6
0
        public void Repository_Keys_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());
            repository.Add("Tester", new object());

            var keyList = new List <string>(repository.Keys);

            keyList.Count.Should().Be(2);
        }
Esempio n. 7
0
        public void AddItemTest()
        {
            var rep   = new TestRepository();
            var items = GetTestItems();

            rep.Add(items.First());
        }
Esempio n. 8
0
        public void RecentMessages()
        {
            var repository = new TestRepository();

            // create a player with some messages
            var player = new Player();
            repository.Add(player);
            var message1 = new Message() { PlayerId = player.Id };
            var message2 = new Message() { PlayerId = player.Id };
            var message3 = new Message() { PlayerId = player.Id };
            var message4 = new Message() { PlayerId = player.Id };
            var message5 = new Message() { PlayerId = player.Id };
            repository.Add(message1);
            repository.Add(message2);
            repository.Add(message3);
            repository.Add(message4);
            repository.Add(message5);

            // verify that the correct messages are returned and in the correct order
            var expectedMessages = new Message[] { message5, message4, message3 }.Select(x => x.Id);
            var recentMessages = player.RecentMessages(3).Select(x => x.Id);
            Assert.AreEqual(expectedMessages, recentMessages);

            // add more messages
            var message6 = new Message() { PlayerId = player.Id };
            var message7 = new Message() { PlayerId = player.Id };
            repository.Add(message6);
            repository.Add(message7);

            // verify that the correct messages are returned and in the correct order
            expectedMessages = new Message[] { message7, message6, message5 }.Select(x => x.Id);
            recentMessages = player.RecentMessages(3).Select(x => x.Id);
            Assert.AreEqual(expectedMessages, recentMessages);
        }
Esempio n. 9
0
        public void ShouldAddWhenEntityToAddIsNotNull()
        {
            const int testId = 14;

            var testObject = new TestObject
            {
                Id = testId,
            };

            var moqDbSet = new Mock <DbSet <TestObject> >();

            moqDbSet.Setup(mdbs => mdbs.Add(testObject)).Returns(testObject);

            var moqDbContext = new Mock <IDatabaseContext>();

            var testRepository = new TestRepository <TestObject>(moqDbContext.Object, moqDbSet.Object);

            var result = testRepository.Add(testObject);

            Assert.NotNull(result);
            Assert.Equal(result.Id, testObject.Id);

            moqDbContext.Verify(mdbc => mdbc.SaveChanges(), Times.Once);
            moqDbSet.Verify(mdbs => mdbs.Add(testObject), Times.Once);
        }
Esempio n. 10
0
        public void CloneSpace()
        {
            var repository = new TestRepository();

            // create a space
            var space = new Space() { BackgroundColorId = 1, BoardId = 2, Height = 3, ImageId = 4, Order = 5, TextColorId = 6, Type = SpaceType.TurnAround, Width = 7, X = 8, Y = 9, IconId = 11 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space was cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.BackgroundColorId, space.BackgroundColorId);
            Assert.AreEqual(clonedSpace.BoardId, space.BoardId);
            Assert.AreEqual(clonedSpace.Height, space.Height);
            Assert.AreEqual(clonedSpace.ImageId, space.ImageId);
            Assert.AreEqual(clonedSpace.Name, space.Name);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreEqual(clonedSpace.TextColorId, space.TextColorId);
            Assert.AreEqual(clonedSpace.Type, space.Type);
            Assert.AreEqual(clonedSpace.Width, space.Width);
            Assert.AreEqual(clonedSpace.X, space.X);
            Assert.AreEqual(clonedSpace.Y, space.Y);
            Assert.AreEqual(clonedSpace.IconId, space.IconId);
        }
Esempio n. 11
0
        public override void TestInitialize()
        {
            base.TestInitialize();
            coaches   = new TestRepository();
            entries   = new TestTimetableEntriesRepository();
            trainings = new TestTrainingsRepository();
            locations = new TestLocationsRepository();
            types     = new TestTrainingTypesRepository();
            data      = GetRandom.Object <CoachData>();
            var c = new Coach(data);

            coaches.Add(c).GetAwaiter();
            trainingData = GetRandom.Object <TrainingData>();
            var t = new Training(trainingData);

            trainings.Add(t).GetAwaiter();
            trainingTypeData = GetRandom.Object <TrainingTypeData>();
            var tt = new TrainingType(trainingTypeData);

            types.Add(tt).GetAwaiter();
            locationData = GetRandom.Object <LocationData>();
            var l = new Location(locationData);

            locations.Add(l).GetAwaiter();
            obj = new TestClass(coaches, entries, trainings, locations, types);
        }
        static void Main(string[] args)
        {
            TestRepository testRepository = new TestRepository();

            testRepository.Add(new EntityLogin {
                UserName = "******", Password = ("123456").ToMD5()
            });
            Console.WriteLine("OK");
        }
Esempio n. 13
0
        public void Repository_Clear_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());
            repository.Clear();

            repository.Count.Should().Be(0);
        }
        public FootlooseFSTestUnitOfWork()
        {
            List<Person> persons = TestDataStore.GetPersonTestData();

            _persons = new TestRepository<Person>();

            foreach (Person person in persons)
                _persons.Add(person);
        }
Esempio n. 15
0
        public void Repository_Contains_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());

            var result = repository.Contains("Test");

            result.Should().BeTrue();
        }
Esempio n. 16
0
        public void CloneSafeHavenSpace()
        {
            var repository = new TestRepository();

            // create a space with a safe haven card
            var safeHavenCard = new SafeHavenCard() { Name = "test1" };
            repository.Add(safeHavenCard);
            var space = new Space() { SafeHavenCardId = safeHavenCard.Id, Order = 10 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and subobject were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.SafeHavenCardId, space.SafeHavenCardId);
            Assert.AreEqual(clonedSpace.SafeHavenCard.Name, space.SafeHavenCard.Name);
        }
Esempio n. 17
0
        public void CloneNameCard()
        {
            var repository = new TestRepository();

            // create a name card
            var image = new Image() { Filename = "test1" };
            repository.Add<Image>(image);
            var nameCard = new NameCard() { Name = "test1", Details = "test2", ImageId = image.Id };
            repository.Add<NameCard>(nameCard);

            // clone the name card
            var clonedCard = nameCard.Clone();

            // verify that the name card was cloned
            Assert.AreNotEqual(nameCard.Id, clonedCard.Id);
            Assert.AreEqual(nameCard.Name, clonedCard.Name);
            Assert.AreEqual(nameCard.Details, clonedCard.Details);
            Assert.AreNotEqual(nameCard.ImageId, clonedCard.ImageId);
        }
Esempio n. 18
0
        public override void TestInitialize()
        {
            base.TestInitialize();
            trainingTypes = new TestRepository();
            data          = GetRandom.Object <TrainingTypeData>();
            var l = new TrainingType(data);

            trainingTypes.Add(l).GetAwaiter();
            obj = new TestClass(trainingTypes);
        }
Esempio n. 19
0
        public void Repository_GetNoMatch_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());

            var result = repository.Get("tester");

            result.Should().BeNull();
        }
Esempio n. 20
0
        public void Repository_DeleteMatch_Test()
        {
            var repository = new TestRepository();

            repository.Add("Test", new object());

            var result = repository.Delete("Test");

            result.Should().BeTrue();
        }
Esempio n. 21
0
        public void CloneChallengeSpace()
        {
            var repository = new TestRepository();

            // create a space with a name card
            var nameCard = new NameCard() { Name = "test1" };
            repository.Add(nameCard);
            var space = new Space() { NameCardId = nameCard.Id, Order = 10 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and subobject were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.NameCardId, space.NameCardId);
            Assert.AreEqual(clonedSpace.NameCard.Name, space.NameCard.Name);
        }
Esempio n. 22
0
        public void CloneSafeHavenCard()
        {
            var repository = new TestRepository();

            // create a safe haven card
            var image = new Image() { Filename = "test1" };
            repository.Add(image);
            var safeHavenCard = new SafeHavenCard() { Name = "test1", Details = "test2", ImageId = image.Id };
            repository.Add(safeHavenCard);

            // clone the safe haven card
            var clonedCard = safeHavenCard.Clone();

            // verify that the safe haven card was cloned
            Assert.AreNotEqual(safeHavenCard.Id, clonedCard.Id);
            Assert.AreEqual(safeHavenCard.Name, clonedCard.Name);
            Assert.AreEqual(safeHavenCard.Details, clonedCard.Details);
            Assert.AreNotEqual(safeHavenCard.ImageId, clonedCard.ImageId);
        }
Esempio n. 23
0
        public override void TestInitialize()
        {
            base.TestInitialize();
            locations = new TestRepository();
            data      = GetRandom.Object <LocationData>();
            var l = new Location(data);

            locations.Add(l).GetAwaiter();
            obj = new TestClass(locations);
        }
        public void CanSetStateOfExternalInstance()
        {
            var writeTimeRespository = new TestRepository();
            var writeTimeInstance = new ClassB(3);
            var xmlText = SerializeAsXml(new ClassA(writeTimeInstance), writeTimeRespository);

            var readTimeRepository = new TestRepository();
            var readTimeInstance = new ClassB(23);
            readTimeRepository.Add(readTimeInstance.GetType(), readTimeInstance);
            var readClass = ReadXmlText<ClassA>(xmlText, readTimeRepository, null, null);
            Assert.AreSame(readTimeInstance, readClass.Parameter);
            Assert.AreEqual(3, readClass.Parameter.Parameter);
        }
Esempio n. 25
0
        public void TurnAround()
        {
            // set up data
            var repository = new TestRepository();

            var board = new Board();
            repository.Add(board);
            var space = new Space() { Type = SpaceType.TurnAround, BoardId = board.Id };
            repository.Add(space);
            var game = new Game();
            game.Repository = repository;
            game.Create(board.Id, 2);

            // trigger onland
            var player = game.Players.First();
            space.OnLand(player);

            // verify that player was turned around and received the correct message
            player = repository.Get<Player>(player.Id);
            Assert.AreEqual(false, player.MovementDirection);
            var message = player.Messages.Single();
            Assert.AreEqual("Turned around.", message.Text);
        }
Esempio n. 26
0
        public void ShouldReturnNullWhenEntityToAddIsNull()
        {
            var moqDbSet = new Mock <DbSet <TestObject> >();

            var moqDbContext = new Mock <IDatabaseContext>();

            var testRepository = new TestRepository <TestObject>(moqDbContext.Object, moqDbSet.Object);

            var result = testRepository.Add(null);

            Assert.Null(result);
            moqDbContext.Verify(mdbc => mdbc.SaveChanges(), Times.Never);
            moqDbSet.Verify(mdbs => mdbs.Add(null), Times.Never);
        }
Esempio n. 27
0
        public void DeleteEmptyGame()
        {
            var repository = new TestRepository();

            // create a game without players or used challenges
            var game = new Game();
            repository.Add(game);

            // delete the game
            game.Delete();

            // verify that deletion works
            Assert.IsEmpty(repository.Find<Game>(x => x.Id == game.Id));
        }
Esempio n. 28
0
        public void MultipleChoiceAnswer()
        {
            var repository = new TestRepository();

            // create a multiple choice challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3 };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // verify that correct answer is acknowledged as correct
            Assert.True(challenge.CorrectAnswer(answer1.Id));
            Assert.False(challenge.CorrectAnswer(answer2.Id));
        }
Esempio n. 29
0
        public void CanSetStateOfExternalInstance()
        {
            var writeTimeRespository = new TestRepository();
            var writeTimeInstance    = new ClassB(3);
            var xmlText = SerializeAsXml(new ClassA(writeTimeInstance), writeTimeRespository);

            var readTimeRepository = new TestRepository();
            var readTimeInstance   = new ClassB(23);

            readTimeRepository.Add(readTimeInstance.GetType(), readTimeInstance);
            var readClass = ReadXmlText <ClassA>(xmlText, readTimeRepository, null, null);

            Assert.AreSame(readTimeInstance, readClass.Parameter);
            Assert.AreEqual(3, readClass.Parameter.Parameter);
        }
Esempio n. 30
0
        public void Init()
        {
            Entity = new TestEntity
                {
                    Id = 0,
                    DateCreated = DateTime.Now,
                    CreatedByUserId = 1,
                    IsActive = true,
                    Name = "Some Test Name"
                };

            Repository = new TestRepository();

            Repository.Add(Entity);
        }
Esempio n. 31
0
        public void CloneEmptyBoard()
        {
            var repository = new TestRepository();

            // create a board without any associated data
            var board = new Board();
            board.Name = "test1";
            repository.Add(board);

            // clone the board
            var clonedBoard = board.Clone();

            // verify that the board is cloned
            Assert.AreNotEqual(board.Id, clonedBoard.Id);
            Assert.AreEqual(board.Name, clonedBoard.Name);
        }
Esempio n. 32
0
        public void CanAddEntity()
        {
            // Arrange
            var entity = new TestEntity { Id = 123, PropOne = "One", PropTwo = 2 };
            var repo = new TestRepository( Session );

            // Act
            repo.Add( entity );

            // Assert

            var fromDb = Session.Get<TestEntity>( entity.Id );

            Assert.IsNotNull( fromDb );
            Assert.AreEqual( entity.PropOne, fromDb.PropOne );
            Assert.AreEqual( entity.PropTwo, fromDb.PropTwo );
        }
Esempio n. 33
0
 public ActionResult Create(Test model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.Acceleration = accelerationService.CalculateAcceleration((float)model.TimeToHundred);
             testRepository.Add(model);
             return(RedirectToAction("Edit", "Car", new { id = model.CarId }));
         }
         catch
         {
             return(View(model));
         }
     }
     return(View(model));
 }
        public void AddTest()
        {
            //Arrange
            var            dataStorage = new Mock <IDataStorage>();
            TestRepository repository  = new TestRepository(dataStorage.Object);
            List <Entity>  list        = new List <Entity>();

            dataStorage.Setup(ds => ds.GetData <Entity>()).Returns(list);

            var entity = new Entity()
            {
                Id = 3
            };

            //Act
            repository.Add(entity);
            //Assert
            Assert.That(list.Count, Is.EqualTo(1));
            Assert.That(list[0].Id, Is.EqualTo(3));
        }
Esempio n. 35
0
        public void Password()
        {
            var repository = new TestRepository();

            // create a player with a password
            var player = new Player();
            repository.Add(player);
            player.SetPassword("testpass123");

            // verify that a correct password is verified
            Assert.True(player.VerifyPassword("testpass123"));

            // verify that an incorrect password is not verified
            Assert.False(player.VerifyPassword("wrongpassword"));

            // verify that an empty password is not verified
            Assert.False(player.VerifyPassword(""));

            // verify that a null password is not verified
            Assert.False(player.VerifyPassword(null));
        }
Esempio n. 36
0
        public void CloneChallenge()
        {
            var repository = new TestRepository();

            // create a challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3, OpenEnded = true };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // clone the challenge
            var clonedChallenge = challenge.Clone();

            // verify that challenge and answers were cloned
            Assert.AreNotEqual(challenge.Id, clonedChallenge.Id);
            Assert.AreEqual(challenge.Question, clonedChallenge.Question);
            Assert.AreEqual(challenge.ChallengeCategoryId, clonedChallenge.ChallengeCategoryId);
            Assert.AreEqual(challenge.OwnerId, clonedChallenge.OwnerId);
            Assert.AreEqual(challenge.OpenEnded, clonedChallenge.OpenEnded);
            Assert.AreNotEqual(challenge.Answers.Select(x => x.Id), clonedChallenge.Answers.Select(x => x.Id));
            Assert.AreEqual(challenge.Answers.Select(x => x.Answer), clonedChallenge.Answers.Select(x => x.Answer));
            Assert.AreEqual(challenge.Answers.Select(x => x.Correct), clonedChallenge.Answers.Select(x => x.Correct));
        }
Esempio n. 37
0
        public void ExportRepositoryToJson()
        {
            // arrange
            var key     = Constants.Json.Key;
            var setting = new JsonSetting {
                Location = _path, Name = "test-repo.json"
            };
            var testRepo = new TestRepository {
                MyProperty = "hello test"
            };
            var rand = new Random();

            for (int i = 0; i < 10; i++)
            {
                testRepo.Add(rand.NextDouble());
            }

            // act & assert export

            var result = _io.Exporter(key)
                         .Setup(setting)
                         .Build(testRepo)
                         .Export();

            Assert.IsNotNull(result, $"{key} export failed");

            // act & assert import

            var importedRepo = _io.Importer(key)
                               .Setup(setting)
                               .Import()
                               .As <TestRepository>();

            Assert.AreEqual(testRepo.MyProperty, importedRepo.MyProperty, $"{key} import failed");
            Log.Info($"{key} success", this);
        }
Esempio n. 38
0
 private Board CreateBoardData(TestRepository repository)
 {
     var image = new Image() { Filename = "test.jpg" };
     repository.Add(image);
     var board = new Board() { ImageId = image.Id, Active = true, Description = "test1", Name = "test3", OwnerId = 4, TurnsToEnd = 50, NameCardsToEnd = 10, SafeHavenCardsToEnd = 5 };
     repository.Add(board);
     var space1 = new Space() { BoardId = board.Id, Order = 10 };
     var space2 = new Space() { BoardId = board.Id, Order = 20 };
     var space3 = new Space() { BoardId = board.Id, Order = 30 };
     repository.AddAll(new Space[] { space1, space2, space3 });
     var category1 = new ChallengeCategory() { Name = "test1", OwnerId = 2 };
     var category2 = new ChallengeCategory() { Name = "test3", OwnerId = 4 };
     var category3 = new ChallengeCategory() { Name = "test4", OwnerId = 4 };
     var categories = new ChallengeCategory[] { category1, category2, category3 };
     repository.AddAll(categories);
     repository.Add(new SpaceChallengeCategory() { SpaceId = space1.Id, ChallengeCategoryId = category1.Id });
     repository.Add(new SpaceChallengeCategory() { SpaceId = space2.Id, ChallengeCategoryId = category3.Id });
     var challenge1 = new Challenge() { Question = "test1", ChallengeCategoryId = category1.Id, OwnerId = 3 };
     var challenge2 = new Challenge() { Question = "test2", ChallengeCategoryId = category2.Id, OwnerId = 4 };
     repository.AddAll(new Challenge[] { challenge1, challenge2 });
     repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id });
     repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id });
     return board;
 }
Esempio n. 39
0
        public void DeletedSpaceWithCategories()
        {
            var repository = new TestRepository();

            // create a space with category links
            var space = new Space();
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 1 });
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 2 });

            // delete a space
            space.Delete();

            // verify that space is deleted
            Assert.IsEmpty(repository.Find<Space>(x => x.Id == space.Id));

            // verify that category links are deleted
            Assert.IsEmpty(repository.Find<SpaceChallengeCategory>(x => x.SpaceId == space.Id));
        }
Esempio n. 40
0
        public void OpenEndedAnswer()
        {
            var repository = new TestRepository();

            // create an open ended challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3, OpenEnded = true };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // verify that correct answer is acknowledged as correct
            Assert.True(challenge.CorrectAnswer(answer1.Answer));
            Assert.False(challenge.CorrectAnswer(answer2.Answer));
            Assert.False(challenge.CorrectAnswer(answer1.Answer + "a"));
        }
Esempio n. 41
0
        public void DeleteEmptyBoard()
        {
            var repository = new TestRepository();

            // create a board without any associated data
            var board = new Board();
            repository.Add(board);

            // verify that deletion works
            board.Delete();
            Assert.IsEmpty(repository.Find<Board>(x => x.Id == board.Id));
        }
Esempio n. 42
0
        // POST: api/TestAPI
        public void Post([FromBody] TestClass testClass)
        {
            TestRepository testrepo = new TestRepository();

            testrepo.Add(testClass);
        }
Esempio n. 43
0
        public void GetNewSpaceNoSpace()
        {
            var repository = new TestRepository();

            // create a board without spaces
            var board = new Board();
            repository.Add(board);

            // verify that an exception is raised when trying to move
            Assert.Catch<Exception>(() => board.GetNewSpace(0, 1, true));
        }
Esempio n. 44
0
        public void GetNewSpace()
        {
            var repository = new TestRepository();

            // create a board with some spaces
            var board = new Board();
            repository.Add(board);
            var space1 = new Space() { BoardId = board.Id, Order = 10 };
            var space2 = new Space() { BoardId = board.Id, Order = 20 };
            var space3 = new Space() { BoardId = board.Id, Order = 30 };
            var space4 = new Space() { BoardId = board.Id, Order = 40 };
            var space5 = new Space() { BoardId = board.Id, Order = 50 };
            repository.AddAll(new Space[] { space1, space2, space3, space4, space5 });

            // verify that the correct space is returned moving forward
            Assert.AreEqual(space2.Id, board.GetNewSpace(space1.Id, 1, true).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space1.Id, 2, true).Id);
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 4, true).Id);

            // verify that the correct space is returned moving forward and wrapping around
            Assert.AreEqual(space1.Id, board.GetNewSpace(space5.Id, 1, true).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space4.Id, 4, true).Id);

            // verify that the correct space is returned moving forward and moving more than the number of spaces
            Assert.AreEqual(space1.Id, board.GetNewSpace(space1.Id, 5, true).Id);
            Assert.AreEqual(space2.Id, board.GetNewSpace(space1.Id, 11, true).Id);

            // verify that the correct space is returned moving backward
            Assert.AreEqual(space4.Id, board.GetNewSpace(space5.Id, 1, false).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space5.Id, 2, false).Id);
            Assert.AreEqual(space1.Id, board.GetNewSpace(space5.Id, 4, false).Id);

            // verify that the correct space is returned moving backward and wrapping around
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 1, false).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space2.Id, 4, false).Id);

            // verify that the correct space is returned moving backward and moving more than the number of spaces
            Assert.AreEqual(space1.Id, board.GetNewSpace(space1.Id, 5, false).Id);
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 11, false).Id);
        }
Esempio n. 45
0
        public void GetNextChallengeMultipleBoardCategories()
        {
            var repository = new TestRepository();

            // create a game with some challenges
            var board = new Board();
            repository.Add(board);
            var game = new Game() { BoardId = board.Id };
            repository.Add(game);
            var category1 = new ChallengeCategory();
            var category2 = new ChallengeCategory();
            repository.Add(category1);
            repository.Add(category2);
            var challenge1 = new Challenge() { ChallengeCategoryId = category1.Id };
            var challenge2 = new Challenge() { ChallengeCategoryId = category1.Id };
            var challenge3 = new Challenge() { ChallengeCategoryId = category2.Id };
            var challenge4 = new Challenge() { ChallengeCategoryId = category2.Id };
            var challenge5 = new Challenge() { ChallengeCategoryId = category2.Id };
            var challenges = new Challenge[] { challenge1, challenge2, challenge3, challenge4, challenge5 };
            repository.AddAll(challenges);
            repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id });
            repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id });

            // get some challenges (which ones will be used is indeterminate)
            for (int i = 0; i < 10; i++)
            {
                game.GetNextChallenge(0);
            }
        }
Esempio n. 46
0
        public void GetNewSpaceSingleSpace()
        {
            var repository = new TestRepository();

            // create a board with a single space
            var board = new Board();
            repository.Add(board);
            var space = new Space() { BoardId = board.Id, Order = 10 };
            repository.Add(space);

            // verify that the same space is returned when moving forward
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 1, true).Id);
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 5, true).Id);

            // verify that the same space is returned when moving backward
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 1, false).Id);
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 5, false).Id);
        }
Esempio n. 47
0
        private Game CreateGameData(TestRepository repository)
        {
            // create game
            var board = new Board();
            repository.Add(board);
            repository.Add(new Space() { BoardId = board.Id });
            var game = new Game() { BoardId = board.Id };
            repository.Add(game);

            // add challenges
            var challenge1 = new Challenge();
            var challenge2 = new Challenge();
            var challenge3 = new Challenge();
            var challenge4 = new Challenge();
            repository.AddAll(new Challenge[] { challenge1, challenge2, challenge3, challenge4 });

            // mark some challenges as used
            repository.Add(new UsedChallenge() { GameId = game.Id, ChallengeId = challenge1.Id });
            repository.Add(new UsedChallenge() { GameId = game.Id, ChallengeId = challenge2.Id });

            // add players
            game.AddPlayer();
            game.AddPlayer();
            game.AddPlayer();

            return game;
        }
Esempio n. 48
0
 public ActionResult <Test> AddTest([FromBody] Test test)
 {
     return(_service.Add(test));
 }
Esempio n. 49
0
 public void AddTestObject()
 {
     _testRepository.Add(new TestModel {
     });
     _unitOfWork.Commit();
 }
Esempio n. 50
0
        public void CloneSpaceWithCategories()
        {
            var repository = new TestRepository();

            // create a space with category links
            var space = new Space() { Order = 10 };
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 1 });
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 2 });

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and category links were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.ChallengeCategories.Select(x => x.Id), space.ChallengeCategories.Select(x => x.Id));
            Assert.AreEqual(clonedSpace.ChallengeCategories.Select(x => x.ChallengeCategoryId), space.ChallengeCategories.Select(x => x.ChallengeCategoryId));
        }
Esempio n. 51
0
 public void Add(TestDTO testDto)
 {
     _testRepository.Add(testDto);
 }