예제 #1
0
        public async Task UpdatePublishReport()
        {
            // arrange
            IMongoCollection <Schema> schemas =
                _mongoResource.CreateCollection <Schema>();
            IMongoCollection <SchemaVersion> versions =
                _mongoResource.CreateCollection <SchemaVersion>();
            IMongoCollection <SchemaPublishReport> publishReports =
                _mongoResource.CreateCollection <SchemaPublishReport>();
            IMongoCollection <PublishedSchema> publishedSchemas =
                _mongoResource.CreateCollection <PublishedSchema>();

            var initial = new Schema("foo", "bar");
            await schemas.InsertOneAsync(initial, options : null, default);

            var initialVersion = new SchemaVersion(
                initial.Id,
                "foo",
                DocumentHash.FromSourceText("bar"),
                Array.Empty <Tag>(),
                DateTime.UtcNow);
            await versions.InsertOneAsync(initialVersion, options : null, default);

            var initialReport = new SchemaPublishReport(
                initialVersion.Id, Guid.NewGuid(), Array.Empty <Issue>(),
                PublishState.Published, DateTime.UtcNow);
            await publishReports.InsertOneAsync(initialReport, options : null, default);

            var repository = new SchemaRepository(
                schemas, versions, publishReports, publishedSchemas);

            // act
            await repository.SetPublishReportAsync(new SchemaPublishReport(
                                                       initialReport.Id, initialReport.SchemaVersionId,
                                                       initialReport.EnvironmentId, initialReport.Issues,
                                                       PublishState.Rejected, DateTime.UtcNow));

            // assert
            IReadOnlyDictionary <Guid, SchemaPublishReport> retrieved =
                await repository.GetPublishReportsAsync(new[] { initialReport.Id });

            Assert.Equal(PublishState.Rejected, retrieved[initialReport.Id].State);
        }