Пример #1
0
        public async Task AddVotes_Event_ReturnsCorrectResult()
        {
            const string nameToBeTestedWith         = "TEST_NAME";
            const string dateToBeTestedWith         = "2010-01-01";
            const string personVotingToBeTestedWith = "TEST_PERSON";

            await WithTestDatabase.Run(async context =>
            {
                var repository = new EventRepository(context);

                var entityToBeAdded = new EventEntity
                {
                    Name         = nameToBeTestedWith,
                    DateEntities = new List <DateEntity>
                    {
                        new DateEntity
                        {
                            Date = dateToBeTestedWith
                        }
                    }
                };
                var addedId     = await repository.CreateEventAsync(entityToBeAdded);
                var addedEntity = await repository.GetAsync(addedId);

                Assert.Empty(DomainLogic.GetAllEventParticipants(addedEntity));

                var votes = new AddVoteDto
                {
                    Name  = personVotingToBeTestedWith,
                    Votes = new List <string> {
                        dateToBeTestedWith
                    }
                };
                var modifiedEvent = await repository.AddVotesAsync(votes.ToEventEntity(addedId));

                Assert.Single(DomainLogic.GetAllEventParticipants(modifiedEvent));

                var suitableDates = DomainLogic.CalculateSuitableDatesForEvent(modifiedEvent.DateEntities,
                                                                               DomainLogic.GetAllEventParticipants(modifiedEvent));
                Assert.Single(suitableDates);
                Assert.Equal(suitableDates.Select(s => s.Date).Single(), dateToBeTestedWith);
            });
        }