Exemplo n.º 1
0
 private async Task InsertDocumentsOf(VersionRange versionRange)
 {
     foreach (var document in versionRange.Documents)
     {
         await InsertDocumentForVersionRange(document, versionRange);
     }
 }
Exemplo n.º 2
0
 public VersionRange Build()
 {
     var versionRange = new VersionRange(firstVersion, lastVersion).WithId(id);
     foreach (var document in documents) {
         versionRange.AddDocument(document);
     }
     return versionRange;
 }
Exemplo n.º 3
0
 public void SetUp()
 {
     topicRepo = Substitute.For<TopicCommandRepository>();
     var productRepository = Substitute.For<ProductRepository>();
     collisionDetector = Substitute.For<VersionRangeCollisionDetector>(productRepository);
     topicService = new TopicService(topicRepo, collisionDetector);
     anyVersionRange = new VersionRange(fromVersion: anyVersion, toVersion: anyVersion);
     anyProductId = "AnyProductId";
 }
Exemplo n.º 4
0
 public VersionRange ToVersionRange()
 {
     var versionRange = new VersionRange(FromVersion, ToVersion);
     foreach (var editableDocument in Documents)
     {
         versionRange.Documents.Add(editableDocument.ToDocument());
     }
     return versionRange;
 }
        public async Task save_version_ranges_of_a_topic()
        {
            var versionRange = new VersionRange(fromVersion: version1, toVersion: version1).WithId("FirstVersionRangeId");
            anyTopic.AddVersionRange(versionRange);

            await topicRepository.Save(anyTopic);

            var versionRangeFromRepo = await GetVersionRangeById("FirstVersionRangeId");
            Assert.That(versionRangeFromRepo.FromVersionId, Is.EqualTo(FirstVersionId));
            Assert.That(versionRangeFromRepo.ToVersionId, Is.EqualTo(FirstVersionId));
            Assert.That(versionRangeFromRepo.TopicId, Is.EqualTo("AnyTopicId"));
        }
Exemplo n.º 6
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
         });
 }
Exemplo n.º 7
0
        public void get_corresponding_document_for_a_given_language()
        {
            var versionRange = new VersionRange(
                fromVersion: version2,
                toVersion: version4
            );
            versionRange.AddDocument(spanishDocument);
            versionRange.AddDocument(englishDocument);

            var document = versionRange.GetDocumentIn("es-ES");

            document.ShouldBeEquivalentTo(spanishDocument);
        }
Exemplo n.º 8
0
 private async Task InsertDocumentForVersionRange(Document document, VersionRange versionRange)
 {
     await connection.Execute(@"INSERT INTO Document(DocumentId, Title, Description, Content, Language, VersionRangeId)
                                             VALUES(@DocumentId, @Title, @Description, @Content, @Language, @VersionRangeId);",
         new
         {
             DocumentId = document.DocumentId,
             Title = document.Title,
             Description = document.Description,
             Content = document.Content,
             Language = document.Language,
             VersionRangeId = versionRange.VersionRangeId
         });
 }
Exemplo n.º 9
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 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_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 save_documents_foreach_version_range_in_a_topic()
        {
            var versionRange = new VersionRange(fromVersion: version1, toVersion: version1).WithId("AnyVersionRangeId");
            anyTopic.AddVersionRange(versionRange);
            versionRange.AddDocument(
                new Document("AnyTitle", "AnyDescription", "AnyContent", "es-ES").WithId("AnyDocumentId")
            );

            await topicRepository.Save(anyTopic);

            var documentFromRepo = await GetDocumentById("AnyDocumentId");
            Assert.That(documentFromRepo.Title, Is.EqualTo("AnyTitle"));
            Assert.That(documentFromRepo.Description, Is.EqualTo("AnyDescription"));
            Assert.That(documentFromRepo.Content, Is.EqualTo("AnyContent"));
            Assert.That(documentFromRepo.Language, Is.EqualTo("es-ES"));
            Assert.That(documentFromRepo.VersionRangeId, Is.EqualTo("AnyVersionRangeId"));
        }
        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 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");
        }
 private List<ProductVersion> AllVersionsContainedIn(VersionRange versionRange)
 {
     return Versions.Where(v => versionRange.FromVersion.Release <= v.Release &&
                                v.Release <= versionRange.ToVersion.Release).ToList();
 }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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);
        }
 private RangeWithAllVersions ToRangeWithAllVersions(VersionRange versionRange)
 {
     var versions = AllVersionsContainedIn(versionRange);
     var rangeWithAllVersions = new RangeWithAllVersions(versions, versionRange);
     return rangeWithAllVersions;
 }
Exemplo n.º 25
0
 public RangeWithAllVersions(List<ProductVersion> versions, VersionRange versionRange)
 {
     VersionRange = versionRange;
     Versions = versions;
 }
Exemplo n.º 26
0
 public void AddVersionRange(VersionRange versionRange)
 {
     VersionRanges.Add(versionRange);
 }