Пример #1
0
        public async Task UpdateSchema_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 initial = new Schema("foo", "bar");
            await schemas.InsertOneAsync(initial, options : null, default);

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

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

            // act
            var         updated = new Schema(initial.Id, "bar", "baz");
            Func <Task> action  = () => repository.UpdateSchemaAsync(updated);

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

            ex.Message.MatchSnapshot();
        }
Пример #2
0
        public async Task UpdateSchema()
        {
            // 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 repository = new SchemaRepository(
                schemas, versions, publishReports, publishedSchemas);

            // act
            var updated = new Schema(initial.Id, initial.Name, "abc");
            await repository.UpdateSchemaAsync(updated);

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

            Assert.NotNull(retrieved);
            Assert.Equal(updated.Name, retrieved.Name);
            Assert.Equal(updated.Description, retrieved.Description);
        }