public async Task <Unit> Handle(ActivateBoosterCommand request, CancellationToken cancellationToken)
        {
            if (!_boosterService.AvailableSlots.ContainsKey(request.GuildId))
            {
                throw new InvalidOperationException("Specified guild has no available slots");
            }

            if (!_boosterService.AvailableSlots[request.GuildId].Exists(s => s.Id == request.Slot.Id))
            {
                throw new InvalidOperationException("Specified slot doesn't exist in guild");
            }

            var booster = new ActiveBooster
            {
                GuildId        = request.GuildId,
                ExpirationDate = _dateTime.Now.ToUniversalTime().Add(request.Duration),
                Multiplier     = request.Multiplier,
                Slot           = _context.XPAvailableSlots.First(s => s.Id == request.Slot.Id)
            };

            _boosterService.ActiveBoosters[request.GuildId].Add(booster);

            _context.XPActiveBoosters.Add(booster);
            await _context.SaveChangesAsync(cancellationToken);

            await _discordChannelService.RenameChannel(request.GuildId, request.Slot.ChannelId,
                                                       $"{1 + request.Multiplier}");

            return(Unit.Value);
        }
Ejemplo n.º 2
0
        public async Task ShouldReturnMultiplier_IfMultipleActiveBoostersExist(
            [Range(0.1f, 5f /*lol*/, 0.1f)] float multiplier, [Random(0.1f, 5f, 1)] float otherMultiplier)
        {
            ulong guildId = 6;
            var   booster = new ActiveBooster
            {
                Multiplier = multiplier
            };
            var otherBooster = new ActiveBooster
            {
                Multiplier = otherMultiplier
            };

            var activeBoosters = new Dictionary <ulong, List <ActiveBooster> >
            {
                { guildId, new List <ActiveBooster> {
                      booster, otherBooster
                  } }
            };

            _boosterService.ActiveBoosters.Returns(activeBoosters);

            var command = new GetBoosterMultiplierCommand
            {
                GuildId = guildId
            };

            var result = await _appFixture.SendAsync(command);

            var sum = multiplier + otherMultiplier;

            result.Should().Be(sum);
        }
Ejemplo n.º 3
0
 public static void ShootEventHandler()
 {
     if (ActiveBooster != null)
     {
         ActiveBooster.DecCount();
         ActiveBooster = null;
     }
 }
Ejemplo n.º 4
0
 private static void CheckActiveBooster(ActiveBooster booster, AvailableSlot slot, ulong guildId,
                                        float multiplier,
                                        DateTime expirationDate)
 {
     booster.Slot.Id.Should().Be(slot.Id);
     booster.GuildId.Should().Be(guildId);
     booster.Multiplier.Should().Be(multiplier);
     booster.ExpirationDate.Should().Be(expirationDate);
 }
Ejemplo n.º 5
0
 private void FooterClickEventHandler()
 {
     if (!IsActive && Count > 0)     // activate booster
     {
         ActivateBooster();
     }
     else if (IsActive)              // deactivate booster
     {
         DeActivateBooster();
     }
     else if (!IsActive && Count == 0 && ActiveBooster != null) // open shop
     {
         ActiveBooster.DeActivateBooster();
     }
 }
Ejemplo n.º 6
0
        public async Task ActiveBoostersShouldBeCorrect_WhenPopulatedFromDatabase()
        {
            ulong guildId        = 6;
            ulong channelId      = 7;
            ulong otherChannelId = 8;
            var   multiplier     = 0.5f;
            var   expirationDate = DateTime.Now.ToUniversalTime().AddMinutes(5);
            var   slot           = new AvailableSlot
            {
                Id        = 69,
                GuildId   = guildId,
                ChannelId = channelId
            };
            var otherSlot = new AvailableSlot
            {
                Id        = 70,
                GuildId   = guildId,
                ChannelId = otherChannelId
            };

            var booster = new ActiveBooster
            {
                GuildId        = guildId,
                Slot           = slot,
                Multiplier     = multiplier,
                ExpirationDate = expirationDate
            };

            _dbContext.ConfigureMockDbSet(x => x.XPActiveBoosters, booster);
            _dbContext.ConfigureMockDbSet(x => x.XPQueuedBoosters);
            _dbContext.ConfigureMockDbSet(x => x.XPAvailableSlots, new[] { slot, otherSlot });

            await _appFixture.SendAsync(new PopulateBoosterServiceCommand());

            _activeBoosters.Should().NotBeNull().And.NotBeEmpty();
            _queuedBoosters.Should().NotBeNull();
            _availableSlots.Should().NotBeNull();

            var boosterToCheck = _activeBoosters[guildId].First();

            CheckActiveBooster(boosterToCheck, slot, guildId, multiplier, expirationDate);
        }