示例#1
0
        private Round DummyRound()
        {
            var round = new Round
            {
                Id = Guid.NewGuid(),
                RoundDescription = "TestRound",
            };

            round.AddUserToRound(new RoundUser
            {
                Id   = Guid.NewGuid(),
                User = new User
                {
                    EmailAddress = "*****@*****.**"
                }
            });

            round.AddUserToRound(new RoundUser
            {
                Id   = Guid.NewGuid(),
                User = new User
                {
                    EmailAddress = "*****@*****.**"
                }
            });

            return(round);
        }
示例#2
0
        public async Task <Round> UpdateRound(Round round, IDataStore dataStore)
        {
            if (!await(ValidateRound(dataStore)))
            {
                return(null);
            }

            var usersToRemove
                = round.UsersInRound.Where(p => UsersInRound.All(p2 => p2 != p.User.SimpleId)).ToList();

            usersToRemove.ForEach(round.RemoveUserFromRound);

            var usersToAdd
                = UsersInRound.Where(u => round.UsersInRound.All(r => r.User.SimpleId != u)).ToList();

            usersToAdd.ForEach(x => round.AddUserToRound(_domainUsersForRound.First(y => y.User.SimpleId == x)));

            if (!CheckUsersInRound(round.UsersInRound.Count))
            {
                return(null);
            }

            round.RoundDescription  = RoundDescription;
            round.RoundLocationName = RoundLocationName;
            round.UpdateEvents     += $"|{DateTime.UtcNow} round updated";

            return(round);
        }
示例#3
0
        public async Task UpdateRound_UserMissingFromModelIsRemovedFromRound()
        {
            var userIdList = new List <string> {
                "YYYYwwwww--", "89798hg--", "8987ggv--"
            };

            var existingRound = new Round
            {
                Id = Guid.NewGuid(),
                RoundDescription = "existing round",
            };

            userIdList.ForEach(x => existingRound.AddUserToRound(new RoundUser
            {
                Id   = Guid.NewGuid(),
                User = new User
                {
                    Id       = Guid.NewGuid(),
                    SimpleId = x
                },
            }));

            var model = DummyRoundModel(new List <string> {
                "YYYYwwwww--", "89798hg--"
            });

            var res = await model.UpdateRound(existingRound, _dataStore.Object);

            Assert.Equal(2, res.UsersInRound.Count);
            Assert.DoesNotContain(res.UsersInRound, x => x.User.SimpleId == "8987ggv--");
            Assert.Equal(model.RoundDescription, res.RoundDescription);
            Assert.NotNull(res.UpdateEvents);
        }
示例#4
0
        public async Task <Round> CreateRoundFromModel(IDataStore dataStore)
        {
            if (!await(ValidateRound(dataStore)))
            {
                return(null);
            }

            var round = new Round
            {
                Id                = Guid.NewGuid(),
                CreatedUtc        = DateTime.UtcNow,
                RoundDescription  = RoundDescription,
                RoundLocationName = RoundLocationName
            };

            _domainUsersForRound.ToList().ForEach(x => round.AddUserToRound(x));

            return(round);
        }
示例#5
0
        public async Task UpdateRound_NewUserInModelIsCreatedInRound()
        {
            var userIdList = new List <string> {
                "YYYYwwwww--", "89798hg--"
            };

            _dataStore.Setup(x => x.GetUserBySimpleIdAsync("8987ggv--")).ReturnsAsync(new User {
                SimpleId = "8987ggv--"
            });

            var existingRound = new Round
            {
                Id = Guid.NewGuid(),
                RoundDescription = "existing round",
            };

            userIdList.ForEach(x => existingRound.AddUserToRound(new RoundUser
            {
                Id   = Guid.NewGuid(),
                User = new User
                {
                    Id       = Guid.NewGuid(),
                    SimpleId = x
                },
            }));

            var model = DummyRoundModel(new List <string> {
                "YYYYwwwww--", "89798hg--", "8987ggv--"
            });

            var res = await model.UpdateRound(existingRound, _dataStore.Object);

            Assert.Equal(3, res.UsersInRound.Count);
            Assert.Contains(res.UsersInRound, x => x.User.SimpleId == "8987ggv--");
            Assert.Equal(model.RoundDescription, res.RoundDescription);
            Assert.NotNull(res.UpdateEvents);
        }