protected void Page_Load(object sender, EventArgs e)
        {
            if (Sitecore.Context.Item.InheritsTemplate(DefaultArticlePageItem.TemplateId))
            {
                ObjDefaultArticle = (DefaultArticlePageItem)Sitecore.Context.Item;
            }

            if (ObjDefaultArticle != null)
            {
                //Show Author details
                if (ObjDefaultArticle.AuthorName.Item != null)
                {
                    frAuthorName.Item            = ObjDefaultArticle.AuthorName.Item;
                    frAuthorImage.Item           = ObjDefaultArticle.AuthorName.Item;
                    hlAuthorImage.Visible        = true;
                    hlAuthorImage.NavigateUrl    = ObjDefaultArticle.AuthorName.Item.GetUrl();
                    hlAuthorMorePost.Text        = UnderstoodDotOrg.Common.DictionaryConstants.Articles_MorePostsbythisAuthorText;
                    hlAuthorMorePost.NavigateUrl = ObjDefaultArticle.AuthorName.Item.GetUrl();

                    AuthorItem author = (AuthorItem)ObjDefaultArticle.AuthorName.Item;

                    litBioSentence.Text = author.AuthorBioAbstract.Raw;
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Example #2
0
        public void AuthorItem_WithCertificates_ParsedCorrectly()
        {
            // Arrange
            var config          = @"
<configuration>
    <SectionName>
        <author name=""authorName"">
            <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true""  />
        </author>
    </SectionName>
</configuration>";
            var nugetConfigPath = "NuGet.Config";

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);

                // Act and Assert
                var settingsFile = new SettingsFile(mockBaseDirectory);
                var section      = settingsFile.GetSection("SectionName");
                section.Should().NotBeNull();

                section.Items.Count.Should().Be(1);
                var item = section.Items.First() as AuthorItem;

                var expectedItem = new AuthorItem("authorName",
                                                  new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA256, allowUntrustedRoot: true));
                SettingsTestUtils.DeepEquals(item, expectedItem).Should().BeTrue();
            }
        }
        public async Task <Guid?> AddAuthor(AuthorItem item)
        {
            try
            {
                var _authorExists = FindAuthorByAuthSource(item.AuthType, item.SourceId);
                if (_authorExists != null)
                {
                    return(Guid.Empty);
                }
                else
                {
                    item.AuthorId    = Guid.NewGuid();
                    item.CreatedOn   = DateTime.UtcNow;
                    item.ModifiedOn  = DateTime.UtcNow;
                    item.AuthType    = AuthenticationType.GITHUB;
                    item.ActivatedOn = DateTime.UtcNow;
                    item.IsSuspended = false;
                    await _db.CreateDocumentAsync <AuthorItem>(dbName, collectionName, item);

                    return(item.AuthorId);
                }
            }
            catch (Exception e)
            {
                return(Guid.Empty);
            }
        }
Example #4
0
        public async Task ExecuteCommandAsync_RemoveAction_WithTrustedSigner_ExistingSigner_RemovesItSuccesfullyAsync()
        {
            // Arrange
            var trustedSignersProvider = new Mock <ITrustedSignersProvider>();
            var expectedItem           = new AuthorItem("author", new CertificateItem("abc", HashAlgorithmName.SHA256));

            trustedSignersProvider
            .Setup(p => p.GetTrustedSigners())
            .Returns(new List <TrustedSignerItem>()
            {
                expectedItem
            });

            using (var test = Test.Create(TrustedSignersAction.Remove, trustedSignersProvider.Object))
            {
                test.Args.Name = "author";

                // Act
                var result = await test.Runner.ExecuteCommandAsync(test.Args);

                result.Should().Be(0);

                test.Logger.Messages.Should().Contain("Successfully removed the trusted signer 'author'.");

                trustedSignersProvider.Verify(p =>
                                              p.Remove(It.Is <IReadOnlyList <TrustedSignerItem> >(l =>
                                                                                                  l.Count == 1 &&
                                                                                                  SettingsTestUtils.DeepEquals(l.First(), expectedItem))));
            }
        }
Example #5
0
        public void AuthorItem_ElementName_IsCorrect()
        {
            var authorItem = new AuthorItem("authorName",
                                            new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA512));

            authorItem.ElementName.Should().Be("author");
        }
Example #6
0
        public async Task ExecuteCommandAsync_AddAction_WithCertificateFingerprint_WithoutHashAlgorithm_DefaultsToSHA256Async()
        {
            // Arrange
            var trustedSignersProvider = new Mock <ITrustedSignersProvider>();

            trustedSignersProvider
            .Setup(p => p.GetTrustedSigners())
            .Returns(new List <TrustedSignerItem>()
            {
            });

            using (var test = Test.Create(TrustedSignersAction.Add, trustedSignersProvider.Object))
            {
                test.Args.Name = "author";
                test.Args.CertificateFingerprint = "abc";

                // Act
                var result = await test.Runner.ExecuteCommandAsync(test.Args);

                result.Should().Be(0);

                test.Logger.Messages.Should().Contain("Successfully added a trusted author 'author'.");

                var expectedItem = new AuthorItem("author", new CertificateItem("abc", HashAlgorithmName.SHA256));
                trustedSignersProvider.Verify(p =>
                                              p.AddOrUpdateTrustedSigner(It.Is <TrustedSignerItem>(i =>
                                                                                                   SettingsTestUtils.DeepEquals(i, expectedItem))));
            }
        }
Example #7
0
 private bool CheckSearchCondition(string text, AuthorItem item)
 {
     if (text != "")
     {
         string[] tmpSearch = text.Split(' ');
         string   tmpName   = item.Name.ToLower();
         bool     add       = true;
         foreach (var search in tmpSearch)
         {
             if (!tmpName.Contains(search.ToLower()))
             {
                 add = false;
                 break;
             }
         }
         if (add)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }
Example #8
0
 public BookDetail(BookRepository bookRepository)
 {
     this.Id       = bookRepository.Id;
     this.Name     = bookRepository.Name;
     this.Sinopsis = bookRepository.Sinopsis;
     this.Authorid = bookRepository.Authorid;
     this.Author   = (new AuthorItem(bookRepository.Author));
 }
Example #9
0
        public void AuthorItem_Equals_WithDifferentName_ReturnsFalse()
        {
            var author1 = new AuthorItem("authorName",
                                         new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA512));
            var author2 = new AuthorItem("otherAuthorName",
                                         new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA512));

            author1.Equals(author2).Should().BeFalse();
        }
Example #10
0
        public void AuthorItem_Equals_WithSameName_ReturnsTrue()
        {
            var author1 = new AuthorItem("authorName",
                                         new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA512));
            var author2 = new AuthorItem("authorName",
                                         new CertificateItem("xyz", Common.HashAlgorithmName.SHA512));

            author1.Equals(author2).Should().BeTrue();
        }
Example #11
0
        private void removeAuthorButton_Click(object sender, EventArgs e)
        {
            AuthorItem selected = (AuthorItem)authorsListbox.SelectedItem;

            if (selected != null)
            {
                m_context.RemoveAuthor(selected.Id);
                RefreshAuthorList();
            }
        }
Example #12
0
 public IActionResult Create([FromBody] AuthorItem item)
 {
     if (item == null || !ModelState.IsValid)
     {
         //return HttpBadRequest();
         return(new BadRequestObjectResult(_messageInvalidObject));
     }
     AuthorItems.Add(item);
     return(CreatedAtRoute("GetAuthor", new { controller = "Author", id = item.Id }, item));
 }
        public async Task <IActionResult> CreateAuthor(AuthorItem value)
        {
            var authorId = await Repo.AddAuthor(value);

            if (authorId != Guid.Empty)
            {
                return(new OkObjectResult(authorId));
            }
            else
            {
                return(new BadRequestResult());
            }
        }
        public void GetById_ShouldReturnItem()
        {
            var result = _controller.GetById(_JackLondonId) as ObjectResult;

            Assert.IsType(typeof(AuthorItem), result.Value); // IsType with two params
            AuthorItem author = (AuthorItem)result.Value;

            Assert.NotNull(author);
            Assert.Equal("Jack", author.FirstName);
            Assert.Equal("London", author.LastName);

            //Assert.Equal(testProducts.First(f => f.Id == 1).FirstName, author.FirstName);
        }
Example #15
0
 private void RefreshAuthorList()
 {
     if (m_context == null)
     {
         return;
     }
     m_listItems.Clear();
     foreach (var entry in m_context.Authors)
     {
         var item = new AuthorItem(entry);
         m_listItems.Add(item);
     }
     RefreshListBox();
 }
Example #16
0
        /// <summary>
        /// Updates the certificate list of a trusted signer by adding the given certificate.
        /// If the signer does not exists it creates a new one.
        /// </summary>
        /// <remarks>This method defaults to adding a trusted author if the signer doesn't exist.</remarks>
        /// <param name="name">Name of the trusted author.</param>
        /// <param name="fingerprint">Fingerprint to be added to the certificate entry.</param>
        /// <param name="hashAlgorithm">Hash algorithm used to calculate <paramref name="fingerprint"/>.</param>
        /// <param name="allowUntrustedRoot">Specifies if allowUntrustedRoot should be set to true in the certificate entry.</param>
        public void AddOrUpdateTrustedSigner(string name, string fingerprint, HashAlgorithmName hashAlgorithm, bool allowUntrustedRoot)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(name));
            }

            if (string.IsNullOrEmpty(fingerprint))
            {
                throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(fingerprint));
            }

            if (!Enum.IsDefined(typeof(HashAlgorithmName), hashAlgorithm) || hashAlgorithm == HashAlgorithmName.Unknown)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.UnsupportedHashAlgorithm, hashAlgorithm.ToString()));
            }

            var certificateToAdd          = new CertificateItem(fingerprint, hashAlgorithm, allowUntrustedRoot);
            TrustedSignerItem signerToAdd = null;

            var signers = _trustedSignersProvider.GetTrustedSigners();

            foreach (var existingSigner in signers)
            {
                if (string.Equals(existingSigner.Name, name, StringComparison.Ordinal))
                {
                    signerToAdd = existingSigner;

                    break;
                }
            }

            string logMessage = null;

            if (signerToAdd == null)
            {
                signerToAdd = new AuthorItem(name, certificateToAdd);
                logMessage  = Strings.SuccessfullyAddedTrustedAuthor;
            }
            else
            {
                signerToAdd.Certificates.Add(certificateToAdd);
                logMessage = Strings.SuccessfullUpdatedTrustedSigner;
            }

            _trustedSignersProvider.AddOrUpdateTrustedSigner(signerToAdd);

            _logger.Log(LogLevel.Information, string.Format(CultureInfo.CurrentCulture, logMessage, name));
        }
Example #17
0
        private static void InputAuthorFields(BookItem book)
        {
            var authorItem = new AuthorItem();

            Console.WriteLine("Введите имя автора:");
            authorItem.Name = ConsoleExtensions.ReadNotEmptyString();

            Console.WriteLine("Введите фамилию автора:");
            authorItem.Surname = ConsoleExtensions.ReadNotEmptyString();

            Console.WriteLine("Введите отчество автора:");
            authorItem.Patronymic = ConsoleExtensions.ReadNotEmptyString();

            book.Author = authorItem;
        }
        public void Update_ShouldNotUpdateItem_InvalidId()
        {
            string updatedFirstName = "Edgar";
            string updatedLastName  = "Poe";

            var updatedAuthor = new AuthorItem
            {
                Id        = 99999,
                FirstName = updatedFirstName,
                LastName  = updatedLastName
            };
            var result = _controller.Update(99999, updatedAuthor);  // define an unreal number

            Assert.IsType <HttpNotFoundResult>(result);
        }
        public void Create_ShouldInsertItem()
        {
            string insertedFirstName = "TestedInsertFirstName";
            string insertedLastName  = "TestedInsertLastName";

            var insertedAuthor = new AuthorItem
            {
                FirstName = insertedFirstName,
                LastName  = insertedLastName
            };
            var result = (AuthorItem)(_controller.Create(insertedAuthor) as ObjectResult).Value;

            Assert.Equal(insertedFirstName, result.FirstName);
            Assert.Equal(insertedLastName, result.LastName);
        }
Example #20
0
        private List <AuthorItem> GetAuthorItems(Book book)
        {
            var authorItems = new List <AuthorItem>();

            foreach (var bookAuthor in book.BookAuthors)
            {
                var authorItem = new AuthorItem()
                {
                    AuthorId       = bookAuthor.AuthorId,
                    NameAndSurname = bookAuthor.Author.Name + " " + bookAuthor.Author.Surname
                };

                authorItems.Add(authorItem);
            }
            return(authorItems);
        }
Example #21
0
        public void TrustedSigner_WithAuthorsAndRepositories_ParsedCorrectly()
        {
            // Arrange
            var config          = @"
<configuration>
    <SectionName>
        <repository name=""repositoryName"" serviceIndex=""https://api.test/index/"">
            <certificate fingerprint=""abcdefg"" hashAlgorithm=""Sha256"" allowUntrustedRoot=""true""  />
            <owners>test;text</owners>
        </repository>
        <author name=""authorName"">
            <certificate fingerprint=""abcdefg"" hashAlgorithm=""Sha256"" allowUntrustedRoot=""true""  />
        </author>
    </SectionName>
</configuration>";
            var nugetConfigPath = "NuGet.Config";

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);

                // Act and Assert
                var settingsFile = new SettingsFile(mockBaseDirectory);
                var section      = settingsFile.GetSection("SectionName");
                section.Should().NotBeNull();
                var items = section.Items.ToList();

                items.Count.Should().Be(2);

                var trustedSignerItem = items[0] as TrustedSignerItem;
                trustedSignerItem.Name.Should().Be("repositoryName");

                var repositoryitem         = items[0] as RepositoryItem;
                var expectedRepositoryItem = new RepositoryItem("repositoryName", "https://api.test/index/", "test;text",
                                                                new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA256, allowUntrustedRoot: true));
                SettingsTestUtils.DeepEquals(repositoryitem, expectedRepositoryItem).Should().BeTrue();

                trustedSignerItem = items[1] as TrustedSignerItem;
                trustedSignerItem.Name.Should().Be("authorName");

                var authorItem         = items[1] as AuthorItem;
                var expectedAuthorItem = new AuthorItem("authorName",
                                                        new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA256, allowUntrustedRoot: true));
                SettingsTestUtils.DeepEquals(authorItem, expectedAuthorItem).Should().BeTrue();
            }
        }
Example #22
0
        public IActionResult Update(int id, [FromBody] AuthorItem item)
        {
            if (item == null || item.Id != id || !ModelState.IsValid)
            {
                //return HttpBadRequest();
                return(new BadRequestObjectResult(_messageInvalidObject));
            }

            var author = AuthorItems.Find(id);

            if (author == null)
            {
                //return HttpNotFound();
                return(new HttpNotFoundObjectResult(new { Message = _messageNotFound }));
            }

            AuthorItems.Update(item);
            return(new NoContentResult());
        }
        public void Update_ShouldUpdateItem()
        {
            string updatedFirstName = "Джек";
            string updatedLastName  = "Лондон";

            var updatedAuthor = new AuthorItem
            {
                Id        = _JackLondonId,
                FirstName = updatedFirstName,
                LastName  = updatedLastName
            };
            var result = _controller.Update(_JackLondonId, updatedAuthor);

            Assert.IsType <NoContentResult>(result);

            var author = _context.Authors.FirstOrDefault(c => c.Id == _JackLondonId);

            Assert.Equal(updatedFirstName, author.FirstName);
            Assert.Equal(updatedLastName, author.LastName);
        }
Example #24
0
        private void button3_Click(object sender, EventArgs e)
        {
            AddEntityForm dlg = new AddEntityForm();

            dlg.Owner = this;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Author na    = BookServiceClient.instance.Service.addNewAuthor(dlg.NewValue);
                bool   exist = false;
                foreach (object a in listBox1.Items)
                {
                    AuthorItem ai = (AuthorItem)a;
                    if (ai.author.id == na.id)
                    {
                        exist = true;
                        break;
                    }
                }
                if (!exist)
                {
                    listBox1.Items.Add(new AuthorItem(na));
                }
            }
        }
        private static bool AuthorItem_DeepEquals(AuthorItem item1, AuthorItem item2)
        {
            if (!ItemBase_DeepEquals(item1, item2))
            {
                return(false);
            }

            if (item1.Certificates.Count == item2.Certificates.Count)
            {
                var itemsEquals = true;

                var certificate1 = item1.Certificates;
                var certificate2 = item2.Certificates;

                for (var i = 0; i < certificate1.Count; i++)
                {
                    itemsEquals &= DeepEquals(certificate1[i], certificate2[i]);
                }

                return(itemsEquals);
            }

            return(false);
        }
Example #26
0
        public ApiResponse Index([FromQuery] Query query, [FromHeader] Header header)
        {
            if (query.Pagination)
            {
                var             authorsRepo = this.authorApplication.GetList(query.Search, query.Page, query.PerPage);
                int             count       = this.authorApplication.Count(query.Search);
                decimal         pageInCount = ((decimal)count) / query.PerPage;
                PaginationModel paginate    = (new PaginationModel()
                {
                    TotalPage = (int)Math.Ceiling(pageInCount),
                    Page = query.Page,
                    PerPage = query.PerPage,
                    Data = AuthorItem.MapRepo(authorsRepo),
                    Total = count
                });

                return(new ApiResponsePagination(HttpStatusCode.OK, paginate));
            }
            else
            {
                var authorsRepo = this.authorApplication.GetList(query.Search, query.Page, query.PerPage);
                return(new ApiResponseDataList(HttpStatusCode.OK, authorsRepo, authorsRepo.Count));
            }
        }
Example #27
0
        public XNode ToXML()
        {
            XElement xCite = new XElement(Fb2Const.fb2DefaultNamespace + Fb2CiteElementName);

            if (!string.IsNullOrEmpty(ID))
            {
                xCite.Add(new XAttribute("id", ID));
            }
            if (!string.IsNullOrEmpty(Lang))
            {
                xCite.Add(new XAttribute(XNamespace.Xml + "lang", Lang));
            }

            foreach (IFb2TextItem CiteItem in citeData)
            {
                xCite.Add(CiteItem.ToXML());
            }
            foreach (ParagraphItem AuthorItem in textAuthors)
            {
                xCite.Add(AuthorItem.ToXML());
            }

            return(xCite);
        }
 public Task <IActionResult> Post([FromBody] AuthorItem value)
 {
     return(AuthorService.CreateAuthor(value));
 }