public async Task CreateOrAddVersion_ShouldSaveBlueprintGraph_WhenAddingANewBlueprint()
        {
            var owner   = await new UserBuilder().Save(_dbContext);
            var payload = await new PayloadBuilder().WithEncoded(TestData.SimpleBookEncoded).Save(_dbContext);
            var request = new BuildService.CreateRequest(
                owner.UserName,
                "test-1",
                "test blueprint 1",
                "the description",
                new[] { "/belt/balancer", "/state/early game" },
                (payload.Hash, null, null, Enumerable.Empty <GameIcon>()),
                null);

            var result = await _service.CreateOrAddVersion(request, new NullTempCoverHandle(), owner.ToClaimsPrincipal());

            result.Should().BeOfType <BuildService.CreateResult.Success>();

            _dbContext.Builds.Should().HaveCount(1);
            _dbContext.Payloads.Should().HaveCount(1);
            _dbContext.Versions.Should().HaveCount(1);

            var build = ((BuildService.CreateResult.Success)result).Build;

            build.Slug.Should().Be("test-1");
            build.Title.Should().Be("test blueprint 1");
            build.Description.Should().Be("the description");
            build.CreatedAt.ToDateTimeUtc().Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(2));
            build.UpdatedAt.Should().Be(build.CreatedAt);
            build.Tags !.Should().BeEquivalentTo("/belt/balancer", "/state/early game");
        }
Esempio n. 2
0
        public async Task <Build> Save(AppDbContext dbContext, bool clearCache = true)
        {
            if (_owner == null && _ownerBuilder == null)
            {
                throw new Exception("Must set owner.");
            }
            if (_payload == null && _payloadBuilder == null)
            {
                throw new Exception("Must set payload.");
            }

            _owner ??= await _ownerBuilder !.Save(dbContext, clearCache: false);
            _payload ??= await _payloadBuilder !.Save(dbContext, clearCache: false);

            var request = new BuildService.CreateRequest(
                _owner.UserName,
                "simple-book",
                "Simple Blueprint Book",
                null,
                _tags,
                (_payload.Hash, null, null, Enumerable.Empty <GameIcon>()),
                null);

            var service = new BuildService(new NullLogger <BuildService>(), dbContext, TestUtils.Tags.Value);
            var result  = await service.CreateOrAddVersion(request, new NullTempCoverHandle(), _owner.ToClaimsPrincipal());

            result.Should().BeOfType <BuildService.CreateResult.Success>();

            if (clearCache)
            {
                dbContext.ClearCache();
            }

            return(((BuildService.CreateResult.Success)result).Build);
        }