コード例 #1
0
        public async Task <DomainValidationResult <Division> > CreateDivisionAsync(
            Clan clan,
            UserId userId,
            string name,
            string description
            )
        {
            var result = new DomainValidationResult <Division>();

            if (!clan.MemberIsOwner(userId))
            {
                result.AddFailedPreconditionError($"The user ({userId}) isn't the clan owner.");
            }

            if (result.IsValid)
            {
                var division = new Division(clan.Id, name, description);

                clan.CreateDivision(division);

                await _clanRepository.UnitOfWork.CommitAsync();

                return(division);
            }

            return(result);
        }
コード例 #2
0
        public async Task ShouldBeHttpStatusCodeOk()
        {
            // Arrange
            var userId   = new UserId();
            var clan     = new Clan("ClanName", new UserId());
            var division = new Division(clan.Id, "test", "description");

            clan.CreateDivision(division);

            var factory = TestHost.WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, userId.ToString()));

            _httpClient = factory.CreateClient();
            var testServer = factory.Server;

            testServer.CleanupDbContext();

            await testServer.UsingScopeAsync(
                async scope =>
            {
                var clanRepository = scope.GetRequiredService <IClanRepository>();
                clanRepository.Create(clan);
                await clanRepository.UnitOfWork.CommitAsync();
            });

            // Act
            using var response = await this.ExecuteAsync(clan.Id);

            // Assert
            response.EnsureSuccessStatusCode();
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var challengeResponses = await response.Content.ReadAsJsonAsync <DivisionDto[]>();

            challengeResponses.Should().HaveCount(1);
        }
コード例 #3
0
        public async Task ShouldBeHttpStatusCodeBadRequest() // Not the owner bad request
        {
            // Arrange
            var userId   = new UserId();
            var clan     = new Clan("ClanName", new UserId());
            var division = new Division(clan.Id, "test", "description");

            clan.CreateDivision(division);
            var divisionId = clan.Divisions.FirstOrDefault()?.Id;

            var factory = TestHost.WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, userId.ToString()));

            _httpClient = factory.CreateClient();
            var testServer = factory.Server;

            testServer.CleanupDbContext();

            await testServer.UsingScopeAsync(
                async scope =>
            {
                var clanRepository = scope.GetRequiredService <IClanRepository>();
                clanRepository.Create(clan);
                await clanRepository.UnitOfWork.CommitAsync();
            });

            // Act
            using var response = await this.ExecuteAsync(clan.Id, divisionId);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }