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();
        }
        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);
        }
示例#3
0
 public Topic Build()
 {
     var topic = new Topic(productId).WithId(topicId);
     foreach (var versionRange in versionRanges) {
         topic.AddVersionRange(versionRange);
     }
     return topic;
 }
示例#4
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>();
        }
示例#5
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>();
        }
示例#6
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 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 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 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();
        }
        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 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 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 save_documents_for_each_of_its_version_ranges()
        {
            var topic = new Topic("PapyrusId").WithId("TopicId");
            await sqlInserter.Insert(topic);

            var versionRange = new VersionRange(version1, version2).WithId("VersionRangeId");
            versionRange.AddDocument(new Document("Título", "Descripción", "Contenido", "es-ES").WithId("DocumentId"));
            topic.AddVersionRange(versionRange);
            await sqlTopicRepository.Update(topic);

            var newVersionRange = (await dbConnection.Query<Document>(@"SELECT Title, Description, Content, Language  
                                                    FROM Document 
                                                    WHERE VersionRangeId = @VersionRangeId",
                                                    new { VersionRangeId = "VersionRangeId" })).FirstOrDefault();
            newVersionRange.Title.Should().Be("Título");
            newVersionRange.Description.Should().Be("Descripción");
            newVersionRange.Content.Should().Be("Contenido");
            newVersionRange.Language.Should().Be("es-ES");
        }
示例#16
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 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 detect_collision_when_to_version_is_defined_with_wildcard() {
            var topic = new Topic(ProductId);
            topic.AddVersionRange(new VersionRange(version3, version4));
            topic.AddVersionRange(new VersionRange(version4, new LastProductVersion()));

            var collision = await versionRangeCollisionDetector.CollisionsFor(topic);

            var expectedCollisions = new List<Collision>
            {
                new Collision(
                    new EditableVersionRange { FromVersion = version3, ToVersion = version4 },
                    new EditableVersionRange { FromVersion = version4, ToVersion = new LastProductVersion()}
                )
            };

            collision.ShouldBeEquivalentTo(expectedCollisions);
        }
        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();
        }
示例#20
0
 public Topic ToTopic()
 {
     var topic = new Topic(Product.ProductId).WithId(TopicId);
     foreach (var editableVersionRange in VersionRanges)
     {
         topic.AddVersionRange(editableVersionRange.ToVersionRange());
     }
     return topic;
 }
        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);
        }
示例#22
0
        public async Task fail_when_trying_to_update_a_topic_without_id()
        {
            var topic = new Topic(anyProductId);
            topic.AddVersionRange(anyVersionRange);

            Func<Task> update = async () => await topicService.Update(topic);

            update.ShouldThrow<CannotUpdateTopicsWithoutTopicIdDeclaredException>();
        }
        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);
        }
示例#24
0
        public async Task update_a_topic_of_the_library()
        {
            var topic = new Topic(anyProductId)
                .WithId("AnyTopicId");
            topic.AddVersionRange(anyVersionRange);
            collisionDetector.CollisionsFor(topic).Returns(Task.FromResult(new List<Collision>()));

            await topicService.Update(topic);

            topicRepo.Received().Update(topic);
        }