Example #1
0
            public async void Should_return_Throw_and_return_BadRequest_with_created_Stats()
            {
                //Arrange
                var expectedResult = new Stats()
                {
                    Time = 30
                };

                var finalResult = new StatsRequest()
                {
                    Time = 30
                };

                StatsRepository
                .Setup(l => l.Add(expectedResult)).Throws(new Exception());


                UnitofWorkMock
                .Setup(m => m.Stats)
                .Returns(StatsRepository.Object);

                MapperMock
                .Setup(m => m.Map <Stats>(finalResult))
                .Returns(expectedResult);

                //Act
                var result = await _uut.Post(finalResult);

                //Assert
                StatsRepository.VerifyAll();
                MapperMock.Verify();

                var ErrorResult = Assert.IsType <BadRequestObjectResult>(result);

                Assert.Equal(400, ErrorResult.StatusCode);
            }
Example #2
0
            public async void Should_Return_OkObjectResult_with_one_Stat()
            {
                //Arrange
                var expectedResult = new Stats()
                {
                    StatsId = 1, Time = 20
                };

                var finalResult = new StatsResponse()
                {
                    StatsId = 1, Time = 30
                };

                StatsRepository
                .Setup(x => x.Get(expectedResult.StatsId))
                .ReturnsAsync(expectedResult).Verifiable();

                UnitofWorkMock
                .Setup(m => m.Stats)
                .Returns(StatsRepository.Object);

                MapperMock
                .Setup(m => m.Map <StatsResponse>(expectedResult))
                .Returns(finalResult);

                //Act
                var result = await _uut.Get(expectedResult.StatsId);

                //Assert
                StatsRepository.Verify();
                MapperMock.VerifyAll();

                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(finalResult, okResult.Value);
            }
Example #3
0
            public async void Should_return_CreatedAtActionResult_with_created_Stats()
            {
                //Arrange
                var expectedResult = new Stats()
                {
                    Time = 30
                };

                var finalResult = new StatsRequest()
                {
                    Time = 30
                };

                StatsRepository
                .Setup(l => l.Add(expectedResult)).Verifiable();


                UnitofWorkMock
                .Setup(m => m.Stats)
                .Returns(StatsRepository.Object);

                MapperMock
                .Setup(m => m.Map <Stats>(finalResult))
                .Returns(expectedResult);

                //Act
                var result = await _uut.Post(finalResult);

                //Assert
                StatsRepository.VerifyAll();
                MapperMock.VerifyAll();

                var response = Assert.IsType <OkObjectResult>(result);

                Assert.Same(finalResult, response.Value);
            }
            public async void Should_Return_OkObjectResult_with_one_Queue()
            {
                //Arrange
                var expectedResult = new Queue()
                {
                    QueueId = 1
                };

                var finalResult = new QueueResponse()
                {
                    QueueId = 1
                };

                QueueRepositoryMock
                .Setup(x => x.Get(expectedResult.QueueId))
                .ReturnsAsync(expectedResult).Verifiable();

                UnitofWorkMock
                .Setup(m => m.Queue)
                .Returns(QueueRepositoryMock.Object);

                MapperMock
                .Setup(m => m.Map <QueueResponse>(expectedResult))
                .Returns(finalResult);

                //Act
                var result = await _uut.Get(expectedResult.QueueId);

                //Assert
                QueueRepositoryMock.Verify();
                MapperMock.Verify();

                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(finalResult, okResult.Value);
            }
Example #5
0
            public async void Should_Add_user_to_chosen_Game()
            {
                //Arrange
                var expectedgameId    = 1;
                var expectedplayer1Id = 1;
                var expectedplayer2Id = 2;


                var expectedgame = new Game
                {
                    GameId  = expectedgameId,
                    Players = new List <Player>
                    {
                        new Player
                        {
                            PlayerId = expectedplayer1Id
                        },
                        new Player
                        {
                            PlayerId = expectedplayer2Id
                        }
                    }
                };

                var expectedgameresponse = new GameResponse
                {
                    GameId  = expectedgameId,
                    Players = new List <PlayerResponse>
                    {
                        new PlayerResponse
                        {
                            PlayerId = expectedplayer1Id
                        },
                        new PlayerResponse
                        {
                            PlayerId = expectedplayer2Id
                        }
                    }
                };

                GameRepositoryMock
                .Setup(x => x.AddUserToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id))
                .ReturnsAsync(expectedgame);

                UnitofWorkMock
                .Setup(m => m.Game)
                .Returns(GameRepositoryMock.Object);

                MapperMock
                .Setup(s => s.Map <GameResponse>(expectedgame))
                .Returns(expectedgameresponse);

                //Act
                var result = await _uut.AddUsersToGame(expectedgameId, expectedplayer1Id, expectedplayer2Id);

                //Assert
                GameRepositoryMock.Verify();
                MapperMock.Verify();

                var response = Assert.IsType <OkObjectResult>(result);

                Assert.Same(expectedgameresponse, response.Value);
            }