Beispiel #1
0
        public async Task AddSchema_DuplicateName()
        {
            // 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);

            // act
            Func <Task> action = () => repository.AddSchemaAsync(schema);

            // assert
            DuplicateKeyException ex = await Assert.ThrowsAsync <DuplicateKeyException>(action);

            ex.Message.MatchSnapshot();
        }
Beispiel #2
0
        public async Task AddSchema()
        {
            // 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");

            // act
            await repository.AddSchemaAsync(schema);

            // assert
            Schema retrieved = await schemas.AsQueryable()
                               .Where(t => t.Id == schema.Id)
                               .FirstOrDefaultAsync();

            Assert.NotNull(retrieved);
            Assert.Equal(schema.Name, retrieved.Name);
            Assert.Equal(schema.Description, retrieved.Description);
        }
        public async Task UpdateSchemaVersion()
        {
            // arrange
            IMongoCollection <Schema> schemas =
                _mongoResource.CreateCollection <Schema>();
            IMongoCollection <SchemaVersion> versions =
                _mongoResource.CreateCollection <SchemaVersion>();
            IMongoCollection <SchemaPublishReport> publishReports =
                _mongoResource.CreateCollection <SchemaPublishReport>();

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

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

            await repository.AddSchemaVersionAsync(schemaVersion);

            var updatedSchemaVersion = new SchemaVersion(
                schemaVersion.Id,
                schema.Id,
                "baz",
                "qux",
                new[]
            {
                new Tag("a", "b", DateTime.UtcNow)
            },
                DateTime.UtcNow);

            // act
            await repository.UpdateSchemaVersionAsync(updatedSchemaVersion);

            // assert
            SchemaVersion retrieved = await versions.AsQueryable()
                                      .Where(t => t.Id == schemaVersion.Id)
                                      .FirstOrDefaultAsync();

            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(updatedSchemaVersion.SourceText, retrieved.SourceText);
            Assert.Equal(updatedSchemaVersion.Hash, retrieved.Hash);
            Assert.Equal(updatedSchemaVersion.Tags.Count, retrieved.Tags.Count);
        }
Beispiel #4
0
        public async Task GetMultipleSchemaVersions()
        {
            // 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 a = new SchemaVersion(
                schema.Id,
                "bar",
                new DocumentHash("baz", "baz", HashFormat.Hex),
                new[]
            {
                new Tag("a", "b", DateTime.UtcNow)
            },
                DateTime.UtcNow);
            await repository.AddSchemaVersionAsync(a);

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

            // act
            IReadOnlyDictionary <Guid, SchemaVersion> retrieved =
                await repository.GetSchemaVersionsAsync(new[] { a.Id, b.Id });

            // assert
            Assert.True(retrieved.ContainsKey(a.Id));
            Assert.True(retrieved.ContainsKey(b.Id));
        }
Beispiel #5
0
        public async Task UpdateSchemaVersion()
        {
            // 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
            await repository.UpdateSchemaVersionTagsAsync(
                schemaVersion.Id,
                new[]
            {
                new Tag("a", "b", DateTime.UtcNow),
                new Tag("a", "c", DateTime.UtcNow)
            });

            // assert
            SchemaVersion retrieved = await versions.AsQueryable()
                                      .Where(t => t.Id == schemaVersion.Id)
                                      .FirstOrDefaultAsync();

            Assert.Equal(2, retrieved.Tags.Count);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public async Task GetSchemaVersion_By_Hash()
        {
            // 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",
                DocumentHash.FromSourceText("bar"),
                new[]
            {
                new Tag("a", "b", DateTime.UtcNow)
            },
                DateTime.UtcNow);
            await repository.AddSchemaVersionAsync(schemaVersion);

            // act
            SchemaVersion retrieved = await repository.GetSchemaVersionByHashAsync(
                schemaVersion.Hash.Hash);

            // 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);
        }