Ejemplo n.º 1
0
        public async Task AddReward_WithNullReward_ShouldThrowException()
        {
            RewardAddingBindingModel rewardModel = null;

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(
                () => this.service.AddReward(rewardModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Add(RewardAddingBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            int id = await this.rewardsService.AddReward(model);

            return(RedirectToAction("Details", new { id }));
        }
Ejemplo n.º 3
0
        public async Task AddReward_WithCorrectReward_ShouldWorkProperly()
        {
            const string name        = "Reward Testing Name";
            const string description = "Rewards Description";

            var rewardModel = new RewardAddingBindingModel()
            {
                Name        = "Reward Testing Name",
                Description = "Rewards Description",
                ImageUrl    = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png",
                Event       = "Gergiovden"
            };

            await this.service.AddReward(rewardModel);

            var reward = this.context.Rewards.First();

            Assert.AreEqual(name, reward.Name);
            Assert.AreEqual(description, reward.Description);
        }
Ejemplo n.º 4
0
        public async Task <int> AddReward(RewardAddingBindingModel model)
        {
            Event @event = DbContext.Events.FirstOrDefault(e => e.Name == model.Event);

            if (@event == null)
            {
                throw new ArgumentException();
            }

            Reward reward = new Reward()
            {
                Name        = model.Name,
                Description = model.Description,
                EventId     = @event.Id,
                ImageUrl    = model.ImageUrl
            };

            await this.DbContext.Rewards.AddAsync(reward);

            await this.DbContext.SaveChangesAsync();

            return(reward.Id);
        }
Ejemplo n.º 5
0
        public async Task AddReward_WithCorrectFewReward_ShouldAddProperly()
        {
            var firstRewardModel = new RewardAddingBindingModel()
            {
                Name        = "First Reward Testing Name",
                Description = "Rewards Description",
                ImageUrl    = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png",
                Event       = "Gergiovden"
            };

            var secondRewardModel = new RewardAddingBindingModel()
            {
                Name        = "Second Reward Testing Name",
                Description = "Second Rewards Description",
                ImageUrl    = "https://dveri.bg/cache/new5/6/1687d8c0fb11c8f4e2a1d603e65e6e1a.png",
                Event       = "Gergiovden"
            };

            await this.service.AddReward(firstRewardModel);

            await this.service.AddReward(secondRewardModel);

            Assert.AreEqual(2, this.context.Rewards.Count());
        }