Example #1
0
        public async Task ShouldReturnNumberOfConnections()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem {
                Url = Guid.NewGuid().ToString(), NumberOfConnections = 0
            };

            matchListItemService.AddMatchListItem(matchListItem);

            int numberOfConnectionsToAdd = new Random().Next(0, 10);

            for (int i = 0; i < numberOfConnectionsToAdd; i++)
            {
                matchListItemService.AddConnection(matchListItem.Url);
            }

            var handler = new GetNumberOfConnectionsByUrlQueryHandler(matchListItemService);

            //Act
            int numberOfConnections = await handler.Handle(new GetNumberOfConnectionsByUrlQuery { Url = matchListItem.Url }, CancellationToken.None);

            //Assert
            numberOfConnections.Should().Be(numberOfConnectionsToAdd);
        }
        public async Task ShouldAddConnection()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            int startNumberOfConnections = new Random().Next();

            MatchListItem matchListItem = new MatchListItem
            {
                Id                  = Guid.NewGuid().ToString(),
                Url                 = Guid.NewGuid().ToString(),
                Name                = "Game",
                Password            = "******",
                NumberOfConnections = startNumberOfConnections
            };

            matchListItemService.AddMatchListItem(matchListItem);

            var handler = new AddConnectionCommandHandler(matchListItemService);

            //Act
            await handler.Handle(new AddConnectionCommand { Url = matchListItem.Url }, CancellationToken.None);

            //Assert
            int numberOfConnections = matchListItemService.GetMatchById(matchListItem.Id).NumberOfConnections;

            int expectedNumberOfConnections = startNumberOfConnections + 1;

            numberOfConnections.Should().Be(expectedNumberOfConnections);
        }
Example #3
0
        public async Task ShouldReturnMatchListItems()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem
            {
                Id       = Guid.NewGuid().ToString(),
                Url      = Guid.NewGuid().ToString(),
                Name     = "Game",
                Password = "******",
            };

            matchListItemService.AddMatchListItem(matchListItem);

            var handler = new GetAllMatchListItemsQueryHandler(matchListItemService);

            //Act
            List <MatchListItem> matchListItems = await handler.Handle(new GetAllMatchListItemsQuery(), CancellationToken.None);

            //Assert
            matchListItems.Should().NotBeNull();
            matchListItems.Should().HaveCount(1);
            matchListItems.First().Should().Be(matchListItem);
        }
Example #4
0
        public async Task SholdThrowError_IfMatchListItemIsInvalid()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem();

            var handler = new AddMatchListItemCommandHandler(matchListItemService);

            //Assert
            Assert.ThrowsAsync <ValidationException>(async() =>
            {
                await handler.Handle(new AddMatchListItemCommand {
                    MatchListItem = matchListItem
                }, CancellationToken.None);
            });
        }
        public async Task ShouldAddMatchListItem()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem();

            var handler = new AddMatchListItemCommandHandler(matchListItemService);

            //Act
            await handler.Handle(new AddMatchListItemCommand { MatchListItem = matchListItem }, CancellationToken.None);

            //Assert
            MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id);

            result.Should().NotBeNull();
            result.Should().Be(matchListItem);
        }
Example #6
0
        public async Task ShouldRemoveMatchListItem()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem {
                Url = Guid.NewGuid().ToString()
            };

            var handler = new RemoveMatchByUrlCommandHandler(matchListItemService);

            //Act
            await handler.Handle(new RemoveMatchByUrlCommand { Url = matchListItem.Url }, CancellationToken.None);

            //Assert
            MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id);

            result.Should().BeNull();
        }
Example #7
0
        public async Task ShouldReturnMatchListItemById()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem {
                Id = Guid.NewGuid().ToString()
            };

            matchListItemService.AddMatchListItem(matchListItem);

            var handler = new GetMatchByIdQueryHandler(matchListItemService);

            //Act
            MatchListItem result = await handler.Handle(new GetMatchByIdQuery { Id = matchListItem.Id }, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            result.Id.Should().Be(matchListItem.Id);
        }
Example #8
0
        public async Task ShouldAddMatchListItem()
        {
            //Arrange
            IMatchListItemsService matchListItemService = new MatchListItemsService();

            MatchListItem matchListItem = new MatchListItem
            {
                Id       = Guid.NewGuid().ToString(),
                Url      = Guid.NewGuid().ToString(),
                Name     = "Game",
                Password = "******",
            };

            var handler = new AddMatchListItemCommandHandler(matchListItemService);

            //Act
            await handler.Handle(new AddMatchListItemCommand { MatchListItem = matchListItem }, CancellationToken.None);

            //Assert
            MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id);

            result.Should().NotBeNull();
            result.Should().Be(matchListItem);
        }