Пример #1
0
    public async Task CanEditTeam()
    {
        var newEvent  = (await EventControllerTest.GetEventController().Add(new DtoEvent {
            Description = "New Event"
        })).Value;
        var newPerson = (await PersonControllerTest.GetPersonController().Add(new DtoPerson {
            Name = "Adam"
        })).Value;
        var newTeam   = new DtoTeam {
            Name = "TeamGeorge", Description = "George", OwnerID = newPerson.ID, EventID = newEvent.ID
        };
        var dtoTeam = (await GetTeamController().Add(newTeam)).Value;

        var editedTeam = dtoTeam with {
            Description = "Changed", DonationTarget = 1234
        };

        await GetTeamController().Edit(editedTeam);

        var returnedTeam = (await GetTeamController().GetByID(editedTeam.ID)).Value;

        returnedTeam.Description.Should().Be(editedTeam.Description);
        returnedTeam.DonationTarget.Should().Be(1234);
    }
}
Пример #2
0
    public async Task SetUp()
    {
        newEvent = await createEvent();

        person = await createPerson();

        team = await createTeam(person, newEvent.ID);
    }
    public async Task SetUp()
    {
        eventController = EventControllerTest.GetEventController();
        testEvent       = (await eventController.Add(new DtoEvent
        {
            Date = new DateTime(1775, 7, 2),
            Description = "Independence",
            Location = "Philly",
            Title = "Sign Here"
        })).Value;

        unassignedDonation = new DtoDonation
        {
            EventID = testEvent.ID,
            Amount  = 1_000M,
            Date    = new DateTime(1775, 7, 4)
        };

        donationController = GetDonationController();
        dtoDonation        = (await donationController.Add(unassignedDonation)).Value;

        var personController = PersonControllerTest.GetPersonController();

        team1Owner = (await personController.Add(new DtoPerson {
            Name = "Team 1 Owner"
        })).Value;
        team2Owner = (await personController.Add(new DtoPerson {
            Name = "Team 2 Owner"
        })).Value;

        var teamController = TeamControllerTest.GetTeamController();

        team1 = (await teamController.Add(new DtoTeam {
            Description = "Team1", EventID = testEvent.ID, Name = "Team1", OwnerID = team1Owner.ID
        })).Value;
        team2 = (await teamController.Add(new DtoTeam {
            Description = "Team2", EventID = testEvent.ID, Name = "Team2", OwnerID = team2Owner.ID
        })).Value;


        team1Donations = new[]
        {
            createDonation(testEvent.ID, team1.ID, 100),
            createDonation(testEvent.ID, team1.ID, 200)
        };

        team2Donations = new[]
        {
            createDonation(testEvent.ID, team2.ID, 300),
            createDonation(testEvent.ID, team2.ID, 400)
        };

        foreach (var donation in team1Donations.Union(team2Donations))
        {
            await donationController.Add(donation);
        }
    }
Пример #4
0
    public async Task CanGetDifferentTeam()
    {
        var newEvent  = (await EventControllerTest.GetEventController().Add(new DtoEvent {
            Description = "New Event"
        })).Value;
        var newPerson = (await PersonControllerTest.GetPersonController().Add(new DtoPerson {
            Name = "Adam"
        })).Value;
        var newTeam   = new DtoTeam {
            Name = "TeamGeorge", Description = "George", OwnerID = newPerson.ID, EventID = newEvent.ID
        };
        var dtoTeam = (await GetTeamController().Add(newTeam)).Value;

        var returnedTeam = (await GetTeamController().GetByID(dtoTeam.ID)).Value;

        returnedTeam.Description.Should().Be("George");
    }
Пример #5
0
    public async Task <ActionResult <DtoTeam> > Add([FromBody] DtoTeam dtoTeam)
    {
        log.LogInformation("Adding new dtoTeam {dtoTeam}", dtoTeam);
        if (!ModelState.IsValid)
        {
            return(BadRequest(getModelStateErrorMessage()));
        }

        if (dtoTeam.ID != 0)
        {
            return(BadRequest("Cannot add with a valid id"));
        }

        var team    = mapper.Map <Team>(dtoTeam);
        var newTeam = await teamRepository.AddAsync(team);

        return(mapper.Map <DtoTeam>(newTeam));
    }
Пример #6
0
    public async Task CanCreateTeam()
    {
        var newEvent  = (await EventControllerTest.GetEventController().Add(new DtoEvent {
            Description = "New Event"
        })).Value;
        var newPerson = (await PersonControllerTest.GetPersonController().Add(new DtoPerson {
            Name = "Adam"
        })).Value;
        var newTeam   = new DtoTeam {
            Name = "New Team!", Description = "George", OwnerID = newPerson.ID, EventID = newEvent.ID, DonationTarget = 500
        };
        var dtoTeam = (await GetTeamController().Add(newTeam)).Value;

        dtoTeam.ID.Should().NotBe(0);
        dtoTeam.Description.Should().Be("George");
        dtoTeam.Name.Should().Be("New Team!");
        dtoTeam.DonationTarget.Should().Be(500);
    }
Пример #7
0
    public async Task <IActionResult> Edit([FromBody] DtoTeam dtoTeam)
    {
        log.LogInformation("Editing dtoTeam {dtoTeam}", dtoTeam);
        if (!ModelState.IsValid)
        {
            return(BadRequest(getModelStateErrorMessage()));
        }

        var team = mapper.Map <Team>(dtoTeam);

        if (!await teamRepository.ExistsAsync(team.ID))
        {
            return(NotFound("Team id does not exist"));
        }

        await teamRepository.EditTeamAsync(team);

        return(Ok("Team edit was successful"));
    }
Пример #8
0
    public async Task CanDeleteTeam()
    {
        var newEvent  = (await EventControllerTest.GetEventController().Add(new DtoEvent {
            Description = "New Event"
        })).Value;
        var newPerson = (await PersonControllerTest.GetPersonController().Add(new DtoPerson {
            Name = "Adam"
        })).Value;
        var newTeam   = new DtoTeam {
            Name = "TeamGeorge", Description = "George", OwnerID = newPerson.ID, EventID = newEvent.ID
        };
        var dtoTeam      = (await GetTeamController().Add(newTeam)).Value;
        var returnedTeam = (await GetTeamController().GetByID(dtoTeam.ID)).Value;

        await GetTeamController().Delete(returnedTeam.ID);

        var badTeamRequests = await GetTeamController().GetByID(dtoTeam.ID);

        var actual = badTeamRequests.Result as NotFoundObjectResult;

        actual.StatusCode.Should().Be(404);
    }
Пример #9
0
 private async Task <DtoRegistration> createRegistration(DtoPerson owner, DtoTeam team) =>
 (await RegistrationControllerTest.GetRegistrationController().Add(new DtoRegistration {
     Nickname = "Reg1", OwnerID = owner.ID, TeamID = team.ID
 })).Value;