public void ToString_returns_expected_value(string referenceString, string expected) { // ARRANGE var reference = DocumentReference.Parse(referenceString); // ACT / ASSERT reference.ToString().Should().Be(expected); }
public void DocsReference_instances_can_be_compared_to_null() { (DocumentReference.Parse("ref:id") == null).Should().BeFalse(); (null == DocumentReference.Parse("ref:id")).Should().BeFalse(); (DocumentReference.Parse("ref:id") != null).Should().BeTrue(); (null != DocumentReference.Parse("ref:id")).Should().BeTrue(); ((DocumentReference?)null == (DocumentReference?)null).Should().BeTrue(); ((DocumentReference?)null != (DocumentReference?)null).Should().BeFalse(); }
public void Parse_can_parse_self_references(string reference) { // ARRANGE // ACT var parsed = DocumentReference.Parse(reference); // ASSERT parsed .Should().NotBeNull() .And.BeOfType <SelfDocumentReference>(); }
public void Parse_can_parse_same_version_references(string reference, string name) { // ARRANGE var expectedName = new DocumentName(name); // ACT var parsed = DocumentReference.Parse(reference); // ASSERT parsed .Should().NotBeNull() .And.BeOfType <SameVersionDocumentReference>() .Which.Name.Should().Be(expectedName); }
public void Parse_can_parse_fully_qualified_docs_references(string reference, string name, string version) { // ARRANGE var expectedIdentity = new DocumentIdentity(new DocumentName(name), NuGetVersion.Parse(version)); // ACT var parsed = DocumentReference.Parse(reference); // ASSERT parsed .Should().NotBeNull() .And.BeOfType <FullyQualifiedDocumentReference>() .And.Match <FullyQualifiedDocumentReference>(fqr => fqr.Identity == expectedIdentity); }
public void Parse_can_parse_same_name_docs_references(string reference, string version) { // ARRANGE var expectedVersion = NuGetVersion.Parse(version); // ACT var parsed = DocumentReference.Parse(reference); // ASSERT parsed .Should().NotBeNull() .And.BeOfType <SameNameDocumentReference>() .And.Match <SameNameDocumentReference>(r => r.Version == expectedVersion); }
public void TryResolveDocument_returns_null_if_document_cannot_be_resolved(string reference) { // ARRANGE var sut = new DocumentReferenceResolver <string>(); sut.Add(DocumentIdentity.Parse("[email protected]"), "document1"); sut.Add(DocumentIdentity.Parse("[email protected]"), "document2"); // ACT var result = sut.TryResolveDocument(DocumentReference.Parse(reference), "document1"); // ASSERT result.Should().BeNull(); }
public void TryResolveDocument_can_resolved_fully_qualified_references_in_documents_without_identity(string reference) { // ARRANGE var sut = new DocumentReferenceResolver <string>(); sut.Add(DocumentIdentity.Parse("[email protected]"), "document"); // ACT var result = sut.TryResolveDocument(DocumentReference.Parse(reference), "some-other-document"); // ASSERT result .Should().NotBeNull() .And.Be("document"); }
public void TryResolveDocument_returns_expected_document(string id1, string id2, string reference, string expectedResult) { // ARRANGE var sut = new DocumentReferenceResolver <string>(); sut.Add(DocumentIdentity.Parse(id1), "document1"); sut.Add(DocumentIdentity.Parse(id2), "document2"); // ACT var actualResult = sut.TryResolveDocument(DocumentReference.Parse(reference), "document1"); // ASSERT actualResult .Should().NotBeNull() .And.Be(expectedResult); }
public async Task Execute_adds_expected_metadata_from_string_config() { // ARRANGE var input = new TestDocument(); var sut = new SetDocumentReferenceMetadata("name", "1.0"); // ACT var output = await ExecuteAsync(input, sut).SingleAsync(); // ASSERT output.Should().NotBeNull(); output.GetDocumentName().Should().NotBeNull().And.Be(new DocumentName("name")); output.GetDocumentVersion().Should().NotBeNull().And.Be(NuGetVersion.Parse("1.0")); output.GetDocumentIdentity().Should().NotBeNull().And.Be(DocumentIdentity.Parse("[email protected]")); output.GetDocumentReference().Should().NotBeNull().And.Be(DocumentReference.Parse("ref:[email protected]")); }
public async Task Execute_adds_AllDocumentVersions_metadata() { // ARRANGE var inputs = GetInputsFromIdentities("[email protected]", "[email protected]", "[email protected]", "[email protected]"); // ACT var output = (await ExecuteAsync(inputs)).First(); // ASSERT output .Should().ContainSingle(x => x.Key == DocumentReferenceKeys.AllDocumentVersions) .Which.Value .Should().BeAssignableTo <IReadOnlyList <IMetadata> >() .Which .Should().HaveCount(3); var otherVersions = output.GetChildren(DocumentReferenceKeys.AllDocumentVersions); foreach (var item in otherVersions) { item .Should().Contain(x => x.Key == DocumentReferenceKeys.DocumentName) .And.Contain(x => x.Key == DocumentReferenceKeys.DocumentVersion) .And.Contain(x => x.Key == DocumentReferenceKeys.DocumentIdentity); item.GetDocumentName() .Should().NotBeNull() .And.Be(new DocumentName("name1")); } otherVersions[0].GetDocumentVersion().Should().Be(NuGetVersion.Parse("1.0")); otherVersions[0].GetDocumentIdentity().Should().Be(DocumentIdentity.Parse("[email protected]")); otherVersions[0].GetDocumentReference().Should().Be(DocumentReference.Parse("ref:[email protected]")); otherVersions[1].GetDocumentVersion().Should().Be(NuGetVersion.Parse("2.0")); otherVersions[1].GetDocumentIdentity().Should().Be(DocumentIdentity.Parse("[email protected]")); otherVersions[1].GetDocumentReference().Should().Be(DocumentReference.Parse("ref:[email protected]")); otherVersions[2].GetDocumentVersion().Should().Be(NuGetVersion.Parse("3.0")); otherVersions[2].GetDocumentIdentity().Should().Be(DocumentIdentity.Parse("[email protected]")); otherVersions[2].GetDocumentReference().Should().Be(DocumentReference.Parse("ref:[email protected]")); }
public void Comparision_of_two_equal_instances_yield_expected_result(string left, string right) { var leftReference = DocumentReference.Parse(left); var rightReference = DocumentReference.Parse(right); // instances must be equal to themselves Assert.AreEqual(leftReference, leftReference); Assert.AreEqual(rightReference, rightReference); // hash code must be equal Assert.AreEqual(leftReference.GetHashCode(), rightReference.GetHashCode()); Assert.AreEqual(leftReference, rightReference); Assert.AreEqual(rightReference, leftReference); Assert.True(leftReference.Equals(rightReference)); Assert.True(leftReference.Equals((object)rightReference)); Assert.True(rightReference.Equals(leftReference)); Assert.True(rightReference.Equals((object)leftReference)); var isEqual1 = leftReference == rightReference; var isEqual2 = rightReference == leftReference; var isNotEqual1 = leftReference != rightReference; var isNotEqual2 = rightReference != leftReference !; #pragma warning disable CS1718 // Comparison made to same variable var isEqual3 = rightReference == rightReference; var isNotEqual3 = rightReference != rightReference !; #pragma warning restore CS1718 // Comparison made to same variable Assert.True(isEqual1); Assert.True(isEqual2); Assert.True(isEqual3); Assert.False(isNotEqual1); Assert.False(isNotEqual2); Assert.False(isNotEqual3); }
public void Parse_throws_ArgumentException_for_invalid_input(string value) { Action act = () => DocumentReference.Parse(value); act.Should().ThrowExactly <ArgumentException>(); }