Ejemplo n.º 1
0
        public void Handle_UpdateGameDetails_NonExisting()
        {
            var dateTime = new Mock <IDateTime>();

            var command = new UpdateGameDetails()
            {
                ID = 1,
            };

            var updateGameDetailsHandler = new UpdateGameDetailsHandler(NewContext, dateTime.Object);

            Func <Task> act = async() => await updateGameDetailsHandler.Handle(command, CancellationToken.None);

            act.Should().Throw <NotFoundException>();
        }
Ejemplo n.º 2
0
        public async void Handle_UpdateGameDetails_Existing()
        {
            var account         = BogusData.MixedAccounts.Generate();
            var skills          = BogusData.GenerateRandomSkills();
            var skillDictionary = skills.ToDictionary(s => s.Type, s => s.Level);

            using (var context = NewContext)
            {
                context.Accounts.Add(account);
                await context.SaveChangesAsync();
            }

            var now      = DateTime.UtcNow;
            var datetime = new Mock <IDateTime>();

            datetime.Setup(d => d.UtcNow).Returns(now);

            const int daysRemaining = 5;
            var       command       = new UpdateGameDetails
            {
                ID = account.ID,
                MembershipDaysRemaining = daysRemaining,
                Skills = skillDictionary
            };

            var updateGameDetailsHandler = new UpdateGameDetailsHandler(NewContext, datetime.Object);

            await updateGameDetailsHandler.Handle(command, CancellationToken.None);

            var newDate = now.AddDays(daysRemaining);

            var uAccount = await NewContext.Accounts.FindAsync(account.ID);

            uAccount.MemberExpirationDate.Should().Be(newDate);
            uAccount.Skills.Should().BeEquivalentTo(skills);
        }