Пример #1
0
 private async Task ValidateToUpdate(Topic topic)
 {
     if (IsNotDefined(topic.TopicId))
         throw new CannotUpdateTopicsWithoutTopicIdDeclaredException();
     if (HasNotAnyVersionRange(topic))
         throw new CannotUpdateTopicsWithNoVersionRangesException();
     await ValidateVersionRangesCollisionsFor(topic);
 }
Пример #2
0
 private async Task ValidateVersionRangesCollisionsFor(Topic topic)
 {
     var conflictedRanges = (await collisionDetector.CollisionsFor(topic));
     if (conflictedRanges.Any())
     {
         throw new VersionRangesCollisionException(conflictedRanges);
     }
 }
Пример #3
0
 private async Task InsertVersionRangesOf(Topic topic)
 {
     foreach (var versionRange in topic.VersionRanges)
     {
         await InsertVersionRangeForTopic(versionRange, topic);
         await InsertDocumentsOf(versionRange);
     }
 }
Пример #4
0
        public void fail_when_trying_to_save_topics_with_no_ranges()
        {
            var topic = new Topic(anyProductId);

            Func<Task> create = async () => await topicService.Create(topic);

            create.ShouldThrow<CannotSaveTopicsWithNoVersionRangesException>();
        }
Пример #5
0
 public Topic Build()
 {
     var topic = new Topic(productId).WithId(topicId);
     foreach (var versionRange in versionRanges) {
         topic.AddVersionRange(versionRange);
     }
     return topic;
 }
Пример #6
0
        public void fail_when_trying_to_save_topics_with_no_related_product()
        {
            var topic = new Topic(null);
            topic.AddVersionRange(anyVersionRange);

            Func<Task> create = async () => await topicService.Create(topic);

            create.ShouldThrow<CannotSaveTopicsWithNoRelatedProductException>();
        }
Пример #7
0
        public void fail_when_trying_to_save_topics_with_id()
        {
            var topic = new Topic(anyProductId)
                            .WithId("AnyTopicId");
            topic.AddVersionRange(anyVersionRange);

            Func<Task> create = async () => await topicService.Create(topic);

            create.ShouldThrow<CannotSaveTopicsWithDefinedTopicIdException>();
        }
Пример #8
0
 public async Task Save(Topic topic)
 {
     await connection.Execute("INSERT INTO Topic(TopicId, ProductId) VALUES (@TopicId, @ProductId)",
         new
         {
             TopicId = topic.TopicId,
             ProductId = topic.ProductId
         });
     await InsertVersionRangesOf(topic);
 }
Пример #9
0
 private async Task ValidateToSave(Topic topic)
 {
     if (!IsNotDefined(topic.TopicId))
         throw new CannotSaveTopicsWithDefinedTopicIdException();
     if (IsNotDefined(topic.ProductId))
         throw new CannotSaveTopicsWithNoRelatedProductException();
     if (HasNotAnyVersionRange(topic))
         throw new CannotSaveTopicsWithNoVersionRangesException();
     await ValidateVersionRangesCollisionsFor(topic);
 }
        public async Task not_detect_collision_no_ranges_use_same_product_version()
        {
            var topic = new Topic(ProductId);
            topic.AddVersionRange(new VersionRange(version1, version2));
            topic.AddVersionRange(new VersionRange(version3, version4));
            topic.AddVersionRange(new VersionRange(version5, version5));

            var collisions = await versionRangeCollisionDetector.CollisionsFor(topic);

            collisions.Should().BeEmpty();
        }
Пример #11
0
 private async Task InsertVersionRangeForTopic(VersionRange versionRange, Topic topic)
 {
     await connection.Execute(@"INSERT INTO VersionRange(VersionRangeId, FromVersionId, ToVersionId, TopicId)
                                         VALUES (@VersionRangeId, @FromVersionId, @ToVersionId, @TopicId)",
         new
         {
             VersionRangeId = versionRange.VersionRangeId,
             FromVersionId = versionRange.FromVersionId,
             ToVersionId = versionRange.ToVersionId,
             TopicId = topic.TopicId
         });
 }
Пример #12
0
 public async Task Insert(Topic topic)
 {
     await dbConnection.Execute("INSERT INTO Topic(TopicId, ProductId) VALUES (@TopicId, @ProductId)",
         new
         {
             TopicId = topic.TopicId,
             ProductId = topic.ProductId
         });
     foreach (var versionRange in topic.VersionRanges)
     {
         await InsertVersionRangeForTopic(versionRange, topic);
     }
 }
        public async Task delete_topic_from_database()
        {
            var topicId = "TopicId";
            var topic = new Topic("OpportunityId").WithId(topicId);
            await new SqlInserter(dbConnection).Insert(topic);
            
            await topicRepository.Delete(topic.TopicId);

            var topicFromDataBase = (await dbConnection.Query<object>(@"SELECT * FROM Topic 
                                                                        WHERE TopicId = @TopicId",
                                                                        new {TopicId = topicId}))
                                                                        .FirstOrDefault();
            topicFromDataBase.Should().BeNull();
        }
        public async Task save_its_new_version_ranges()
        {
            var topic = new Topic("PapyrusId").WithId("TopicId");
            await sqlInserter.Insert(topic);

            topic.AddVersionRange(new VersionRange(version1, version2).WithId("VersionRangeId"));
            await sqlTopicRepository.Update(topic);

            var newVersionRange = (await dbConnection.Query<dynamic>(@"SELECT FromVersionId, ToVersionId  
                                            FROM VersionRange 
                                            WHERE TopicId = @TopicId",
                                            new { TopicId = "TopicId" })).FirstOrDefault();
            Assert.That(newVersionRange.FromVersionId, Is.EqualTo(version1.VersionId));
            Assert.That(newVersionRange.ToVersionId, Is.EqualTo(version2.VersionId));
        }
        public async Task detect_collision_when_fromversion_of_a_version_range_is_contained_by_other_range()
        {
            var topic = new Topic(ProductId);
            topic.AddVersionRange(new VersionRange(version1, version3));
            topic.AddVersionRange(new VersionRange(version2, version4));

            var collisions = await versionRangeCollisionDetector.CollisionsFor(topic);

            var expectedCollisions = new List<Collision>
            {
                new Collision(
                    new EditableVersionRange { FromVersion = version1, ToVersion = version3 },
                    new EditableVersionRange { FromVersion = version2, ToVersion = version4 }
                )};
            collisions.ShouldAllBeEquivalentTo(expectedCollisions);
        }
Пример #16
0
 private async Task InsertVersionRangeForTopic(VersionRange versionRange, Topic topic)
 {
     await dbConnection.Execute(@"INSERT INTO VersionRange(VersionRangeId, FromVersionId, ToVersionId, TopicId)
                                         VALUES (@VersionRangeId, @FromVersionId, @ToVersionId, @TopicId)",
         new
         {
             VersionRangeId = versionRange.VersionRangeId,
             FromVersionId = versionRange.FromVersionId,
             ToVersionId = versionRange.ToVersionId,
             TopicId = topic.TopicId
         });
     foreach (var document in versionRange.Documents)
     {
         await InsertDocumentForVersionRange(document, versionRange);
     }
 }
        public async Task removes_old_version_ranges_for_given_topic()
        {
            var topic = new Topic("PapyrusId").WithId("TopicId");
            var versionRange = new VersionRange(version1, version2)
                                                .WithId("VersionRangeId");
            topic.AddVersionRange(versionRange);
            await sqlInserter.Insert(topic);

            var topicToUpdate = new Topic("PapyrusId").WithId("TopicId");
            await sqlTopicRepository.Update(topicToUpdate);

            var oldVersionRanges = (await dbConnection.Query<dynamic>(@"SELECT FromVersionId, ToVersionId  
                                            FROM VersionRange 
                                            WHERE VersionRangeId = @VersionRangeId",
                                            new {VersionRangeId = "VersionRangeId"}));
            oldVersionRanges.Should().BeEmpty();
        }
        public async Task delete_its_product_versions_from_database()
        {
            var versionRangeId = "VersionRangeId";
            var versionRange = new VersionRange(anyVersion, anotherVersion)
                                .WithId(versionRangeId);
            var topic = new Topic("OpportunityId").WithId("TopicId");
            topic.AddVersionRange(versionRange);
            await new SqlInserter(dbConnection).Insert(topic);
            
            await topicRepository.Delete(topic.TopicId);

            var versionFromDataBase = (await dbConnection.Query<object>(@"SELECT * FROM VersionRange 
                                                                        WHERE VersionRangeId = @VersionRangeId",
                                                                        new { VersionRangeId = versionRangeId}))
                                                                        .FirstOrDefault();
            versionFromDataBase.Should().BeNull();
        }
        public async Task removes_old_documents_for_given_topic()
        {
            var topic = new Topic("PapyrusId").WithId("TopicId");
            var versionRange = new VersionRange(version1, version2)
                                                .WithId("VersionRangeId");
            var document = new Document("Título", "Descripción", "Contenido", "es-ES").WithId("DocumentId");
            versionRange.AddDocument(document);
            topic.AddVersionRange(versionRange);
            await sqlInserter.Insert(topic);

            var topicToUpdate = new Topic("PapyrusId").WithId("TopicId");
            await sqlTopicRepository.Update(topicToUpdate);

            var oldDocument = (await dbConnection.Query<Document>(@"SELECT Title, Description, Content, Language  
                                            FROM Document 
                                            WHERE DocumentId = @DocumentId",
                                            new { DocumentId = "DocumentId" })).FirstOrDefault();
            oldDocument.Should().BeNull();
        }
        public async Task delete_all_documents_for_each_of_its_product_versions_from_database()
        {
            var documentId = "DocumentId";
            var document = new Document("Título", "Descripción", "Contenido", "es-ES").WithId(documentId);
            var versionRange = new VersionRange(anyVersion, anotherVersion)
                                .WithId("VersionRangeId");
            versionRange.AddDocument(document);
            var topic = new Topic("OpportunityId").WithId("TopicId");
            topic.AddVersionRange(versionRange);
            await new SqlInserter(dbConnection).Insert(topic);
            
            await topicRepository.Delete(topic.TopicId);

            var documentFromDataBase = (await dbConnection.Query<object>(@"SELECT * FROM Document 
                                                                        WHERE DocumentId = @DocumentId",
                                                                        new {DocumentId = documentId}))
                                                                        .FirstOrDefault();
            documentFromDataBase.Should().BeNull();
        }
Пример #21
0
        public void fail_when_try_to_create_a_topic_with_version_ranges_that_collide()
        {
            var topic = new Topic(anyProductId);
            topic.AddVersionRange(anyVersionRange);
            topic.AddVersionRange(anyVersionRange);
            var anyEditableVersionRange = new EditableVersionRange
            {
                FromVersion = new ProductVersion("Any", "2.0", DateTime.Today),
                ToVersion = new ProductVersion("Any", "3.0", DateTime.Today)
            };
            var anyListToRepresentConflictedVersionRanges = new List<Collision> {new Collision(
                anyEditableVersionRange, anyEditableVersionRange
            )};
            collisionDetector.CollisionsFor(topic).Returns(Task.FromResult(anyListToRepresentConflictedVersionRanges));

            Func<Task> createTopic = async () => await topicService.Create(topic);
            
            createTopic.ShouldThrow<VersionRangesCollisionException>()
                .WithMessage("(2.0 -- 3.0) collide with (2.0 -- 3.0)\n");
        }
        public async Task a_list_with_topics_with_wildcard_as_to_version()
        {
            await InsertProductWithItsVersions();
            var topic = new Topic(ProductId).WithId("AnyTopicId");
            var firstVersionRange = new VersionRange(version1, new LastProductVersion()).WithId("AnyRangeId");
            firstVersionRange.AddDocument(spanishDocument.WithId("AnyDocumentId"));
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var topicSummaries = await topicRepository.GetAllTopicsSummariesFor("es-ES");

            topicSummaries.First().VersionName.Should().Be(LastProductVersion.Name);
        }
Пример #23
0
        public async Task save_a_topic_when_it_is_created()
        {
            var topic = new Topic(anyProductId);
            topic.AddVersionRange(anyVersionRange);
            collisionDetector.CollisionsFor(topic).Returns(new List<Collision>());

            await topicService.Create(topic);

            topicRepo.Received().Save(topic);
            topicRepo.Received().Save(Arg.Is<Topic>(t => !String.IsNullOrEmpty(t.TopicId)));
        }
        public async Task get_empty_list_if_there_are_no_documents() {
            await InsertProductWithItsVersions();
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, version1).WithId("FirstVersionRangeId");
            firstVersionRange.AddDocument(spanishDocument.WithId("AnyId"));
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var documents = await topicRepository.GetAllDocumentsFor(ProductId, version1.VersionName, EnglishLanguage);

            documents.Should().HaveCount(0);
        }
        public async Task get_empty_exportable_document_list_if_there_given_version_does_not_exist() {
            await InsertProductWithItsVersions();
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, version1).WithId("FirstVersionRangeId");
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var documents = await topicRepository.GetAllDocumentsFor(ProductId, "No existing Version", EnglishLanguage);

            documents.Should().HaveCount(0);
        }
        public async Task exportable_topic_for_a_given_version_and_language() {
            await InsertProductWithItsVersions();
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, version1).WithId("FirstVersionRangeId");
            var secondVersionRange = new VersionRange(version2, new LastProductVersion()).WithId("SecondVersionRangeId");
            firstVersionRange.AddDocument(spanishDocument.WithId("AnyId"));
            secondVersionRange.AddDocument(new Document("Título", "Descripción", "Contenido", "es-ES").WithId("AnotherId"));
            topic.AddVersionRange(firstVersionRange);
            topic.AddVersionRange(secondVersionRange);
            await sqlInserter.Insert(topic);

            var documents = await topicRepository.GetAllDocumentsFor(ProductId, version1.VersionName, SpanishLanguage);

            documents.Should().HaveCount(1);
            var document = documents.First();
            document.Title.Should().Be(spanishDocument.Title);
            document.Content.Should().Be(spanishDocument.Content);
        }
        public async Task editable_topic_when_to_version_is_a_wildcard() {
            await InsertProduct(ProductId, "any Product");
            var fromVersionId = "anyId";
            await InsertProductVersion(version1, ProductId);
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, new LastProductVersion()).WithId("FirstVersionRangeId");
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var editableTopic = await topicRepository.GetEditableTopicById("FirstTopicPapyrusId");

            (editableTopic.VersionRanges.First().ToVersion is LastProductVersion).Should().BeTrue();
        }
        public async Task a_displayable_topic_with_documents_for_each_of_its_version_ranges()
        {
            await InsertProductWithAVersion();
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, version1).WithId("FirstVersionRangeId");
            spanishDocument.WithId("DocumentId");
            firstVersionRange.AddDocument(spanishDocument);
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var editableTopic = await topicRepository.GetEditableTopicById("FirstTopicPapyrusId");

            var editableVersionRange = editableTopic.VersionRanges.First();
            editableVersionRange.Documents.Should().HaveCount(1);
            var editableDocument = editableVersionRange.Documents.First();
            editableDocument.Title.Should().Be("Título");
            editableDocument.Description.Should().Be("Descripción");
            editableDocument.Content.Should().Be("Contenido");
            editableDocument.Language.Should().Be(SpanishLanguage);
        }
        public async Task a_displayable_topic_with_its_versionRanges()
        {
            await InsertProductWithAVersion();
            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            var firstVersionRange = new VersionRange(version1, version1).WithId("FirstVersionRangeId");
            topic.AddVersionRange(firstVersionRange);
            await sqlInserter.Insert(topic);

            var editableTopic = await topicRepository.GetEditableTopicById("FirstTopicPapyrusId");

            var editableVersionRanges = editableTopic.VersionRanges;
            editableVersionRanges.Should().HaveCount(1);
            editableVersionRanges.First().FromVersion.VersionId.Should().Be(FirstVersionId);
            editableVersionRanges.First().FromVersion.VersionName.Should().Be(FirstVersionName);
            editableVersionRanges.First().ToVersion.VersionId.Should().Be(FirstVersionId);
            editableVersionRanges.First().ToVersion.VersionName.Should().Be(FirstVersionName);
        }
        public async Task a_displayable_topic_with_its_product()
        {
            await InsertProduct(ProductId, "Opportunity");

            var topic = new Topic(ProductId).WithId("FirstTopicPapyrusId");
            await sqlInserter.Insert(topic);

            var editableTopic = await topicRepository.GetEditableTopicById("FirstTopicPapyrusId");

            editableTopic.Product.ProductId.Should().Be(ProductId);
            editableTopic.Product.ProductName.Should().Be("Opportunity");
        }