예제 #1
0
        public async Task GetSchemaVersions()
        {
            // 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 repository = new SchemaRepository(
                schemas, versions, publishReports, publishedSchemas);

            var schema = new Schema("foo", "bar");
            await repository.AddSchemaAsync(schema);

            var schemaVersion = new SchemaVersion(
                schema.Id,
                "bar",
                new DocumentHash("baz", "baz", HashFormat.Hex),
                new[]
            {
                new Tag("a", "b", DateTime.UtcNow)
            },
                DateTime.UtcNow);
            await repository.AddSchemaVersionAsync(schemaVersion);

            // act
            SchemaVersion retrieved = repository.GetSchemaVersions()
                                      .Where(t => t.Id == schemaVersion.Id)
                                      .FirstOrDefault();

            // assert
            Assert.NotNull(retrieved);
            Assert.Equal(schemaVersion.Id, retrieved.Id);
            Assert.Equal(schemaVersion.Published, retrieved.Published, TimeSpan.FromSeconds(1));
            Assert.Equal(schemaVersion.SchemaId, retrieved.SchemaId);
            Assert.Equal(schemaVersion.ExternalId, retrieved.ExternalId);
            Assert.Equal(schemaVersion.Tags.Count, retrieved.Tags.Count);
        }