/// <summary> /// Checks if the exception has a specific property having a specific value. /// </summary> /// <typeparam name="T">Exception type</typeparam> /// <typeparam name="TP">Property type</typeparam> /// <param name="checker">Syntax helper</param> /// <param name="propertyName">Name of property</param> /// <param name="propertyValue">Expected valued of property</param> /// <returns>A chainable check.</returns> public static ICheckLink <ILambdaExceptionCheck <T> > WithProperty <T, TP>(this ILambdaExceptionCheck <T> checker, string propertyName, TP propertyValue) where T : Exception { var found = false; ExtensibilityHelper.BeginCheck(checker as FluentSut <T>) .CantBeNegated("WithProperty") .SetSutName("exception") .CheckSutAttributes(sut => { var type = sut.GetType(); var property = type.GetProperty(propertyName); if (property == null) { return(null); } found = true; return(property.GetValue(sut, null)); }, $"property [{propertyName}]") .FailWhen(_ => !found, $"There is no property [{propertyName}] on exception type [{typeof(T).Name}].", MessageOption.NoCheckedBlock) .FailWhen(sut => !EqualityHelper.FluentEquals(sut, propertyValue), "The {0} does not have the expected value.") .DefineExpectedValue(propertyValue, "", "") .EndCheck(); return(new CheckLink <ILambdaExceptionCheck <T> >(checker)); }
/// <summary> /// Determines whether the specified <see cref="object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="object"/> to compare with this instance.</param> /// <returns><c>true</c> if the specified object is equal to this instance; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { RequestCreate other = obj as RequestCreate; if (other == null) { return(false); } if (!base.Equals(obj)) { return(false); } if (this.CreateMode != other.CreateMode) { return(false); } if (!EqualityHelper.Equals(this.Acl, other.Acl)) { return(false); } return(EqualityHelper.Equals(this.Data, other.Data)); }
public void GetAllSuccessTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); listOfItems[0].CompanyName = "1"; listOfItems[1].CompanyName = "2"; listOfItems[2].CompanyName = "3"; repository.AddRange(listOfItems); unitOfWork.Commit(); //When var allItems = repository.GetAll(); //Then EqualityHelper.AssertListsAreEqual(allItems.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
private EqualityHelper GetHelper() { if (_helper == null) _helper = CreateHelper(); return _helper; }
/// <summary> /// Ends RDF Handling by ensuring the queue of Triples to write has been processed /// </summary> /// <param name="ok">Indicates whether parsing completed without error</param> protected override void EndRdfInternal(bool ok) { //First process the last batch of ground triples (if any) if (this._actions.Count > 0) { this.ProcessBatch(); } //Then process each batch of non-ground triples List <Uri> uris = (from u in this._bnodeUris select(u.Equals(String.Empty) ? null : UriFactory.Create(u))).ToList(); foreach (Uri u in uris) { List <Triple> batch = new List <Triple>(); for (int i = 0; i < this._bnodeActions.Count; i++) { if (EqualityHelper.AreUrisEqual(u, this._bnodeActions[i].GraphUri)) { batch.Add(this._bnodeActions[i]); this._bnodeActions.RemoveAt(i); i--; } } if (u == null) { this._manager.UpdateGraph(this._defaultGraphUri, batch, null); } else { this._manager.UpdateGraph(u, batch, null); } } }
/// <inheritdoc /> public override bool DataEquals(IRingMasterBackendRequest obj) { BackendRequestWithContext<TRequest, TReturn> other = obj as BackendRequestWithContext<TRequest, TReturn>; // note we don't need to validate the request type because the previous check covers us on that if (this.Uid != other?.Uid) { return false; } if (this.ExecutionQueueTimeoutMillis != other.ExecutionQueueTimeoutMillis) { return false; } if (Guid.Equals(this.ExecutionQueueId, other.ExecutionQueueId)) { return false; } if (!string.Equals(this.Path, other.Path)) { return false; } return EqualityHelper.Equals(this.context, other.context); }
public void ShouldServeAsNonGenericIEqualityComparer() { Sample1 obj1 = new Sample1(); EqualityHelper <Sample1> helper = new EqualityHelper <Sample1>(); helper.Add(x => x.IntProp); helper.Add(x => x.StringProp); var hash = new Hashtable(helper); hash.Add(new Sample1() { IntProp = 2, StringProp = "asd" }, "doesn't matter"); hash.ContainsKey(new Sample1() { IntProp = 2, StringProp = "asd" }).Should().Be.True(); hash.ContainsKey(new Sample1() { IntProp = 3, StringProp = "asd" }).Should().Be.False(); }
/// <summary> /// Indicates whether the current Object is equal to another Object of the same type. /// </summary> /// <param name="other">An Object to compare with this Object.</param> /// <returns> /// true if the current Object is equal to the <paramref name="other" /> parameter; otherwise, false. /// </returns> public Boolean Equals(SelectorDescriptor other) { return(EqualityHelper.IsNullOrReferenceEqual(other, this) ?? String.Equals(Value, other.Value) && Enumerable.SequenceEqual(SelectorAttributes, other.SelectorAttributes) && Enumerable.SequenceEqual(PseudoSelectorDescriptors, other.PseudoSelectorDescriptors)); }
public void TestInheritanceOuter() { Sample1 obj1 = new Sample1(); Sample2 obj2 = new Sample2(); EqualityHelper helper = new EqualityHelper(typeof(Sample1)); helper.AddAllProperties(); helper.ObjectEquals(obj1, obj2).Should().Be.True(); obj1.IntProp = obj2.IntProp = 42; helper.ObjectEquals(obj1, obj2).Should().Be.True(); helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode(obj1)); obj1.StringProp = "A"; helper.ObjectEquals(obj1, obj2).Should().Be.False(); obj2.StringProp = "B"; helper.ObjectEquals(obj1, obj2).Should().Be.False(); obj1.StringProp = "B"; helper.ObjectEquals(obj1, obj2).Should().Be.True(); helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode(obj1)); }
public void TestBasicTypesEqualityInner() { Sample1 obj1 = new Sample1(); Sample1 obj2 = new Sample1(); EqualityHelper helper = new EqualityHelper(obj1); helper.Add((Sample1 x) => x.IntProp); helper.Add((Sample1 x) => x.StringProp); helper.ObjectEquals(obj2).Should().Be.True(); obj1.IntProp = obj2.IntProp = 42; helper.ObjectEquals(obj2).Should().Be.True(); helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode()); obj1.StringProp = "A"; helper.ObjectEquals(obj2).Should().Be.False(); obj2.StringProp = "B"; helper.ObjectEquals(obj2).Should().Be.False(); obj1.StringProp = "B"; helper.ObjectEquals(obj2).Should().Be.True(); helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode()); }
static void TestGetBytes(Encoding xEncoding, string xName, string text, byte[] expectedResult, string desc) { byte[] result; result = xEncoding.GetBytes(text); Assert.IsTrue(EqualityHelper.ByteArrayAreEquals(result, expectedResult), $"{xName} Encoding of {desc} text failed byte arrays different"); }
/// <summary> /// Checks that the actual <see cref="IDictionary{K,V}"/> contains the expected expectedKey. /// </summary> /// <typeparam name="TK"> /// The type of the expectedKey element. /// </typeparam> /// <typeparam name="TU">Type for values.</typeparam> /// <param name="check"> /// The fluent check to be extended. /// </param> /// <param name="key"> /// The expected expectedKey value. /// </param> /// <returns> /// A check link. /// </returns> public static ICheckLink <ICheck <IEnumerable <KeyValuePair <TK, TU> > > > ContainsKey <TK, TU>(this ICheck <IEnumerable <KeyValuePair <TK, TU> > > check, TK key) { ExtensibilityHelper.BeginCheck(check). Analyze((sut, test) => { if (sut is IDictionary <TK, TU> dico) { if (dico.ContainsKey(key)) { return; } } #if !DOTNET_20 && !DOTNET_30 && !DOTNET_35 && !DOTNET_40 else if (sut is IReadOnlyDictionary <TK, TU> roDico) { if (roDico.ContainsKey(key)) { return; } } #endif else if (sut.Any(keyValuePair => EqualityHelper.FluentEquals(keyValuePair.Key, key))) { return; } test.Fail("The {0} does not contain the expected key."); }). DefineExpectedResult(key, "Expected key:", "Forbidden key:"). OnNegate("The {0} does contain the given key, whereas it must not."). EndCheck(); return(ExtensibilityHelper.BuildCheckLink(check)); }
public void CreateComparerTest() { List <int> list1 = new List <int>(); for (int i = 0; i < 100; i++) { list1.Add(i); } List <int> list2 = new List <int>(); for (int i = 50; i < 150; i++) { list2.Add(i); } IEqualityComparer <int> comparer = EqualityHelper <int> .CreateComparer(m => m); List <int> list3 = list1.Intersect(list2, comparer).ToList(); Assert.Equal(50, list3.Count); Assert.Equal(50, list3.Min()); Assert.Equal(99, list3.Max()); List <int> list4 = list1.Except(list2, comparer).ToList(); Assert.Equal(50, list4.Count); Assert.Equal(0, list4.Min()); Assert.Equal(49, list4.Max()); EqualityHelper <int> .CreateComparer(m => m, comparer); }
public void UpdateSuccessItemTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); Account testAccount; var repository = new AccountRepository(databseFactory); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { testAccount = repository.Save(AccountEntityHelper.CreateTestAccount()); unitOfWork.Commit(); //When testAccount.CompanyName = "Updated account"; repository.Save(testAccount); unitOfWork.Commit(); } //Then var finalDatabaseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); var finalRepo = new AccountRepository(finalDatabaseFactory); var itemToCheck = finalRepo.GetById(testAccount.AccountID); EqualityHelper.PropertyValuesAreEqual(itemToCheck, testAccount, new[] { "LastModified", "Contacts" }); }
public void GetItemsViaStoredProcedureWithParameterNotParameterisedTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var reference = "TestReference"; var listOfItems = GetItemsWithTwoItemsContainingTestReference(reference); repository.AddRange(listOfItems); unitOfWork.Commit(); //When var filter = new SqlParameter("@CompanyName", SqlDbType.VarChar) { Value = $"%{reference}%" }; var items = repository.ExecuteQuery <Account>("exec GetAccounts @CompanyName", filter).ToList(); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).Take(2).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
private bool IsInvalid(INode n) { if (n.NodeType != NodeType.Literal) { return(true); } var literal = (ILiteralNode)n; var xsd_string = UriFactory.Create(XmlSpecsHelper.XmlSchemaDataTypeString); var rdf_langString = UriFactory.Create(RdfSpecsHelper.RdfLangString); var stringDatatype = string.IsNullOrEmpty(literal.Language) ? xsd_string : rdf_langString; var datatype = literal.DataType ?? stringDatatype; if (!EqualityHelper.AreUrisEqual(datatype, DataTypeParameter)) { return(true); } if (literal.DataType is null) { return(false); } var supportedDatatypes = SparqlSpecsHelper.SupportedCastFunctions.Union(SparqlSpecsHelper.IntegerDataTypes); if (!supportedDatatypes.Contains(literal.DataType.AbsoluteUri)) { return(false); } return(IsIllformed(literal)); }
public async void GetAsyncByName() { // Arrange var expectedCustomers = new Page <Customer> { Items = new Customer[] { customers[5] }, TotalSize = 1 }; CustomersRepositoryMock .Setup(x => x.GetAsyncByName("6")) .ReturnsAsync(expectedCustomers.Items); foreach (Customer customer in customers) { VehiclesRepositoryMock .Setup(x => x.GetByCustomerId(customer.Id, SearchVehicleStatus.Any)) .ReturnsAsync(customer.Vehicles); } // Act var result = await ServiceUnderTest.GetAsyncByName("6", pagingOptions); // Assert Assert.True(EqualityHelper.SamePageOfCustomers(expectedCustomers, result)); }
/// <summary> /// A value indicating whether the specified instance is equal to this instance. /// </summary> /// <param name="other">The other.</param> /// <returns><c>true</c> if the instances are equal.</returns> public bool Equals(VariableFlatIdentifierRepresentation other) { return(EqualityHelper.Equals( this, other, obj => this.VariableExpression.Equals(obj.VariableExpression) && this.Exponent.Equals(obj.Exponent))); }
public void ParsingRdfXmlWithUrlEscapedNodes() { //Originally submitted by Rob Styles as part of CORE-251, modified somewhat during debugging process NTriplesFormatter formatter = new NTriplesFormatter(); RdfXmlParser domParser = new RdfXmlParser(RdfXmlParserMode.DOM); Graph g = new Graph(); domParser.Load(g, "resources\\urlencodes-in-rdfxml.rdf"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Uri encoded = new Uri("http://example.com/some%40encoded%2FUri"); Uri unencoded = new Uri("http://example.com/some@encoded/Uri"); Assert.False(EqualityHelper.AreUrisEqual(encoded, unencoded), "URIs should not be equivalent because %40 encodes a reserved character and per RFC 3986 decoding this can change the meaning of the URI"); IUriNode encodedNode = g.GetUriNode(encoded); Assert.NotNull(encodedNode); IUriNode unencodedNode = g.GetUriNode(unencoded); Assert.NotNull(unencodedNode); IUriNode pred = g.CreateUriNode(new Uri("http://example.org/schema/encoded")); Assert.True(g.ContainsTriple(new Triple(encodedNode, pred, g.CreateLiteralNode("true"))), "The encoded node should have the property 'true' from the file"); Assert.True(g.ContainsTriple(new Triple(unencodedNode, pred, g.CreateLiteralNode("false"))), "The unencoded node should have the property 'false' from the file"); }
public void TestIdentifierListMultipleKey() { var helper = new EqualityHelper <Sample1>(x => x.IntProp, x => x.StringProp); CollectionAssert.AreEquivalent( new[] { "IntProp", "StringProp" }, helper.IdentifierNamesList); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> public Boolean Equals(CommandDescriptor other) { return(EqualityHelper.IsNullOrReferenceEqual(other, this) ?? String.Equals(Name, other.Name) && String.Equals(Description, other.Description) && Enumerable.SequenceEqual(Arguments, other.Arguments) && Enumerable.SequenceEqual(CommandNames, other.CommandNames)); }
/// <summary> /// Checks that the actual <see cref="IDictionary{K,V}"/> is equivalent to a given dictionary. /// </summary> /// <param name="check">The fluent check to be extended.</param> /// <param name="other">Reference dictionary</param> /// <typeparam name="TK">Type for keys.</typeparam> /// <typeparam name="TU">Type for values.</typeparam> /// <returns>A check link.</returns> public static ICheckLink <ICheck <IEnumerable <KeyValuePair <TK, TU> > > > IsEquivalentTo <TK, TU>( this ICheck <IEnumerable <KeyValuePair <TK, TU> > > check, IEnumerable <KeyValuePair <TK, TU> > other) { var checker = ExtensibilityHelper.BeginCheck(check); EqualityHelper.ImplementEquivalentTo(checker, other); return(ExtensibilityHelper.BuildCheckLink(check)); }
public void GetInstrumentationSet_UsesSuppliedInitialContext() { var context = new InstrumentAttribute { Metric = Metric.Scoped, MetricName = "Test metric", Scopes = InstrumentationScopes.All }; _testDiscoverer.GetInstrumentationSet("dummy path", context, x => true); EqualityHelper.AreObjectsEquivalentByPublicProperties(_testDiscoverer.FirstContext, context, false); }
/// <summary> /// Checks that the actual value is not equal to another expected value. /// </summary> /// <typeparam name="T">Type of the struct or the enum to assert on.</typeparam> /// <param name="check">The fluent check to be extended.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A check link. /// </returns> /// <exception cref="FluentCheckException">The actual value is equal to the expected value.</exception> public static ICheckLink <IStructCheck <T> > IsNotEqualTo <T>(this IStructCheck <T> check, object expected) where T : struct { var runnableStructCheck = ExtensibilityHelper.ExtractStructChecker(check); return(runnableStructCheck.ExecuteCheck( () => EqualityHelper.IsNotEqualTo(runnableStructCheck, expected), EqualityHelper.BuildErrorMessage(runnableStructCheck, expected, false))); }
/// <summary> /// Checks that the actual value is not equal to another expected value. /// </summary> /// <typeparam name="T"> /// Type of the checked value. /// </typeparam> /// <param name="check">The fluent check to be extended.</param> /// <param name="expected">The expected value.</param> /// <returns> /// A check link. /// </returns> /// <exception cref="FluentCheckException">The actual value is equal to the expected value.</exception> public static ICheckLink <ICheck <T> > IsNotEqualTo <T>(this ICheck <T> check, object expected) { var checker = ExtensibilityHelper.ExtractChecker(check); return(checker.ExecuteCheck( () => EqualityHelper.IsNotEqualTo(checker, expected), EqualityHelper.BuildErrorMessage(checker, expected, false))); }
/// <summary> /// Checks if the sut contains the same element than a given list. /// </summary> /// <param name="context">Context for the check</param> /// <param name="expectedValues"> expected content</param> /// <typeparam name="T">Type of enumerable content</typeparam> /// <returns>A chainable link.</returns> public static ICheckLink <ICheck <IEnumerable <T> > > IsEquivalentTo <T>(this ICheck <IEnumerable <T> > context, params T[] expectedValues) { var checker = ExtensibilityHelper.BeginCheck(context); EqualityHelper.ImplementEquivalentTo(checker, ExtractEnumerableValueFromPossibleOneValueArray(expectedValues)); return(ExtensibilityHelper.BuildCheckLink(context)); }
/// <summary> /// Checks that the actual value is equal to another expected value. /// </summary> /// <param name="check"> /// The fluent check to be extended. /// </param> /// <param name="expected"> /// The expected value. /// </param> /// <returns> /// A check link. /// </returns> /// <exception cref="FluentCheckException"> /// The actual value is not equal to the expected value. /// </exception> public static ICheckLink <ICheck <long> > IsEqualTo(this ICheck <long> check, long expected) { var checker = ExtensibilityHelper.ExtractChecker <long>(check); return(checker.ExecuteCheck( () => EqualityHelper.IsEqualTo(checker, expected), EqualityHelper.BuildErrorMessage(checker, expected, true))); }
public bool Equals(MusicPlayerEventArgs?other) { return(EqualityHelper.Equals( this, other, rhs => this.StatusEventArgs == rhs.StatusEventArgs && this.VolumeChangedEventArgs == rhs.VolumeChangedEventArgs && this.AudioOutputEventArgs == rhs.AudioOutputEventArgs)); }
/// <summary> /// Handles triples by stripping explicit xsd:string datatype on object literals before delegating to inner handler. /// </summary> protected override bool HandleTripleInternal(Triple t) { if (t.Object is ILiteralNode literal && EqualityHelper.AreUrisEqual(literal.DataType, DataTypeString)) { t = new Triple(t.Subject, t.Predicate, t.Graph.CreateLiteralNode(literal.Value)); } return(_handler.HandleTriple(t)); }
/// <summary> /// Checks that the actual <see cref="IDictionary{K,V}"/> contains the expected value. /// </summary> /// <typeparam name="TK"> /// The type of the expectedKey element. /// </typeparam> /// <typeparam name="TU"> /// Value type. /// </typeparam> /// <param name="check"> /// The fluent check to be extended. /// </param> /// <param name="expectedValue"> /// The expected value. /// </param> /// <returns> /// A check link. /// </returns> public static ICheckLink <ICheck <IEnumerable <KeyValuePair <TK, TU> > > > ContainsValue <TK, TU>(this ICheck <IEnumerable <KeyValuePair <TK, TU> > > check, TU expectedValue) { ExtensibilityHelper.BeginCheck(check). FailWhen(sut => !sut.Any(keyValuePair => EqualityHelper.FluentEquals(keyValuePair.Value, expectedValue)), "The {0} does not contain the expected value."). DefineExpectedResult(expectedValue, "Expected value:", "Forbidden value:"). OnNegate("The {0} does contain the given value, whereas it must not."). EndCheck(); return(ExtensibilityHelper.BuildCheckLink(check)); }
public void GetEffectiveInstrumentationContext_ReturnsContextEquivalentToSupplied_IfOnlyOneNonNullContextSuppliedWithNullsAfter() { var attr = new InstrumentAttribute { IncludeCompilerGeneratedCode = true, Metric = Metric.Scoped, MetricName = "Metric name", Scopes = InstrumentationScopes.All }; var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(attr, null, null); Assert.IsTrue(EqualityHelper.AreObjectsEquivalentByPublicProperties(attr, effective, false)); }