public bool GetObjectNeedsUpate(CustomField checkUpdateFrom) { if (!Name.Equals(checkUpdateFrom.Name)) { return(true); } if (!FieldType.Equals(checkUpdateFrom.FieldType)) { return(true); } if (!ModelType.Equals(checkUpdateFrom.ModelType)) { return(true); } if (!HelpText.Equals(checkUpdateFrom.HelpText)) { return(true); } if (!SortOrder.Equals(checkUpdateFrom.SortOrder)) { return(true); } if (!Options.Equals(checkUpdateFrom.Options)) { return(true); } return(false); }
public bool Equals(IModelIdentifier other) { bool ret = true; ret &= !(other == null); ret &= ModelType.Equals(other.ModelType); ret &= ModelId.SequenceEqual(ModelId); return(ret); }
public override Expression <Func <Trigger, bool> > ToExpression() { Expression <Func <Trigger, bool> > expression = x => ModelType.Equals(x.ModelType); if (!string.IsNullOrWhiteSpace(TenantId)) { expression = expression.And(x => x.TenantId == TenantId); } return(expression); }
public override bool Equals(object obj) { var other = obj as RuleSetKey; if (other == null) { return(false); } return(ModelType.Equals(other.ModelType) && ContextType.Equals(other.ContextType)); }
public void ModelTypeEqualityTests() { Assert.AreNotEqual(ModelType.For("alias1"), ModelType.For("alias1")); Assert.IsTrue(ModelType.Equals(ModelType.For("alias1"), ModelType.For("alias1"))); Assert.IsFalse(ModelType.Equals(ModelType.For("alias1"), ModelType.For("alias2"))); Assert.IsTrue(ModelType.Equals(typeof(IEnumerable <>).MakeGenericType(ModelType.For("alias1")), typeof(IEnumerable <>).MakeGenericType(ModelType.For("alias1")))); Assert.IsFalse(ModelType.Equals(typeof(IEnumerable <>).MakeGenericType(ModelType.For("alias1")), typeof(IEnumerable <>).MakeGenericType(ModelType.For("alias2")))); Assert.IsTrue(ModelType.Equals(ModelType.For("alias1").MakeArrayType(), ModelType.For("alias1").MakeArrayType())); Assert.IsFalse(ModelType.Equals(ModelType.For("alias1").MakeArrayType(), ModelType.For("alias2").MakeArrayType())); }
/// <summary> /// Determines whether the specified <see cref="System.Object" />, is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { if (ReferenceEquals(obj, null)) { return(false); } var target = default(IEngine); if (!obj.GetType().Implements <IProduct>()) { return(false); } target = (IEngine)obj; var isEqual = ModelType.Equals(target.ModelType) && Brand.IsEqualTo(target.Brand) && Price.Equals(target.Price); return(isEqual); }
/// <summary> /// Returns a value indicating whether this instance and a specified System.Guid object represent the same value. /// </summary> /// <param name="obj">An object to compare to this instance.</param> /// <returns>true if g is equal to this instance; otherwise, false.</returns> public override bool Equals(object obj) { var compare = (StoreKey)obj; return(ModelType.Equals(compare.ModelType) && EntityKeys.Equals(compare.EntityKeys)); }
public void SimpleConverter3Test() { Current.Reset(); var register = RegisterFactory.Create(); var composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.WithCollectionBuilder <PropertyValueConverterCollectionBuilder>() .Append <SimpleConverter3A>() .Append <SimpleConverter3B>(); IPublishedModelFactory factory = new PublishedModelFactory(new[] { typeof(PublishedSnapshotTestObjects.TestElementModel1), typeof(PublishedSnapshotTestObjects.TestElementModel2), typeof(PublishedSnapshotTestObjects.TestContentModel1), typeof(PublishedSnapshotTestObjects.TestContentModel2), }); register.Register(f => factory); Current.Factory = composition.CreateFactory(); var cacheMock = new Mock <IPublishedContentCache>(); var cacheContent = new Dictionary <int, IPublishedContent>(); cacheMock.Setup(x => x.GetById(It.IsAny <int>())).Returns <int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null); var publishedSnapshotMock = new Mock <IPublishedSnapshot>(); publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object); var publishedSnapshotAccessorMock = new Mock <IPublishedSnapshotAccessor>(); publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot).Returns(publishedSnapshotMock.Object); register.Register(f => publishedSnapshotAccessorMock.Object); var converters = Current.Factory.GetInstance <PropertyValueConverterCollection>(); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(Mock.Of <ILogger>())) { Id = 1 }, new DataType(new VoidEditor("2", Mock.Of <ILogger>())) { Id = 2 }); var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeService); IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType, int i) { yield return(contentTypeFactory.CreatePropertyType(contentType, "prop" + i, i)); } var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", t => CreatePropertyTypes(t, 1)); var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", t => CreatePropertyTypes(t, 2)); var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", t => CreatePropertyTypes(t, 1)); var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", t => CreatePropertyTypes(t, 2)); var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "val1" } }, false); var element2 = new PublishedElement(elementType2, Guid.NewGuid(), new Dictionary <string, object> { { "prop2", "1003" } }, false); var cnt1 = new SolidPublishedContent(contentType1) { Id = 1003, Properties = new[] { new SolidPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } } }; var cnt2 = new SolidPublishedContent(contentType1) { Id = 1004, Properties = new[] { new SolidPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } } }; cacheContent[cnt1.Id] = cnt1.CreateModel(); cacheContent[cnt2.Id] = cnt2.CreateModel(); // can get the actual property Clr type // ie ModelType gets properly mapped by IPublishedContentModelFactory // must test ModelClrType with special equals 'cos they are not ref-equals Assert.IsTrue(ModelType.Equals(typeof(IEnumerable <>).MakeGenericType(ModelType.For("content1")), contentType2.GetPropertyType("prop2").ModelClrType)); Assert.AreEqual(typeof(IEnumerable <PublishedSnapshotTestObjects.TestContentModel1>), contentType2.GetPropertyType("prop2").ClrType); // can create a model for an element var model1 = factory.CreateModel(element1); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel1>(model1); Assert.AreEqual("val1", ((PublishedSnapshotTestObjects.TestElementModel1)model1).Prop1); // can create a model for a published content var model2 = factory.CreateModel(element2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel2>(model2); var mmodel2 = (PublishedSnapshotTestObjects.TestElementModel2)model2; // and get direct property Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>(model2.Value("prop2")); Assert.AreEqual(1, ((PublishedSnapshotTestObjects.TestContentModel1[])model2.Value("prop2")).Length); // and get model property Assert.IsInstanceOf <IEnumerable <PublishedSnapshotTestObjects.TestContentModel1> >(mmodel2.Prop2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>(mmodel2.Prop2); var mmodel1 = mmodel2.Prop2.First(); // and we get what we want Assert.AreSame(cacheContent[mmodel1.Id], mmodel1); }
public void SimpleConverter3Test() { var register = new ServiceCollection(); var composition = new UmbracoBuilder(register, Mock.Of <IConfiguration>(), TestHelper.GetMockedTypeLoader()); composition.WithCollectionBuilder <PropertyValueConverterCollectionBuilder>() .Append <SimpleConverter3A>() .Append <SimpleConverter3B>(); IPublishedModelFactory factory = new PublishedModelFactory( new[] { typeof(PublishedSnapshotTestObjects.TestElementModel1), typeof(PublishedSnapshotTestObjects.TestElementModel2), typeof(PublishedSnapshotTestObjects.TestContentModel1), typeof(PublishedSnapshotTestObjects.TestContentModel2) }, Mock.Of <IPublishedValueFallback>()); register.AddTransient(f => factory); var cacheMock = new Mock <IPublishedContentCache>(); var cacheContent = new Dictionary <int, IPublishedContent>(); cacheMock.Setup(x => x.GetById(It.IsAny <int>())).Returns <int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null); var publishedSnapshotMock = new Mock <IPublishedSnapshot>(); publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object); var publishedSnapshotAccessorMock = new Mock <IPublishedSnapshotAccessor>(); var localPublishedSnapshot = publishedSnapshotMock.Object; publishedSnapshotAccessorMock.Setup(x => x.TryGetPublishedSnapshot(out localPublishedSnapshot)).Returns(true); register.AddTransient(f => publishedSnapshotAccessorMock.Object); IServiceProvider registerFactory = composition.CreateServiceProvider(); PropertyValueConverterCollection converters = registerFactory.GetRequiredService <PropertyValueConverterCollection>(); var serializer = new ConfigurationEditorJsonSerializer(); var dataTypeServiceMock = new Mock <IDataTypeService>(); var dataType1 = new DataType( new VoidEditor( Mock.Of <IDataValueEditorFactory>()), serializer) { Id = 1 }; var dataType2 = new DataType( new VoidEditor( "2", Mock.Of <IDataValueEditorFactory>()), serializer) { Id = 2 }; dataTypeServiceMock.Setup(x => x.GetAll()).Returns(new[] { dataType1, dataType2 }); var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeServiceMock.Object); IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType, int i) { yield return(contentTypeFactory.CreatePropertyType(contentType, "prop" + i, i)); } IPublishedContentType elementType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "element1", t => CreatePropertyTypes(t, 1)); IPublishedContentType elementType2 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1001, "element2", t => CreatePropertyTypes(t, 2)); IPublishedContentType contentType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1002, "content1", t => CreatePropertyTypes(t, 1)); IPublishedContentType contentType2 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1003, "content2", t => CreatePropertyTypes(t, 2)); var element1 = new PublishedElement( elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "val1" } }, false); var element2 = new PublishedElement( elementType2, Guid.NewGuid(), new Dictionary <string, object> { { "prop2", "1003" } }, false); var cnt1 = new InternalPublishedContent(contentType1) { Id = 1003, Properties = new[] { new InternalPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } } }; var cnt2 = new InternalPublishedContent(contentType1) { Id = 1004, Properties = new[] { new InternalPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } } }; IPublishedModelFactory publishedModelFactory = registerFactory.GetRequiredService <IPublishedModelFactory>(); cacheContent[cnt1.Id] = cnt1.CreateModel(publishedModelFactory); cacheContent[cnt2.Id] = cnt2.CreateModel(publishedModelFactory); // can get the actual property Clr type // ie ModelType gets properly mapped by IPublishedContentModelFactory // must test ModelClrType with special equals 'cos they are not ref-equals Assert.IsTrue(ModelType.Equals( typeof(IEnumerable <>).MakeGenericType(ModelType.For("content1")), contentType2.GetPropertyType("prop2").ModelClrType)); Assert.AreEqual( typeof(IEnumerable <PublishedSnapshotTestObjects.TestContentModel1>), contentType2.GetPropertyType("prop2").ClrType); // can create a model for an element IPublishedElement model1 = factory.CreateModel(element1); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel1>(model1); Assert.AreEqual("val1", ((PublishedSnapshotTestObjects.TestElementModel1)model1).Prop1); // can create a model for a published content IPublishedElement model2 = factory.CreateModel(element2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel2>(model2); var mmodel2 = (PublishedSnapshotTestObjects.TestElementModel2)model2; // and get direct property Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>( model2.Value(Mock.Of <IPublishedValueFallback>(), "prop2")); Assert.AreEqual( 1, ((PublishedSnapshotTestObjects.TestContentModel1[])model2.Value(Mock.Of <IPublishedValueFallback>(), "prop2")).Length); // and get model property Assert.IsInstanceOf <IEnumerable <PublishedSnapshotTestObjects.TestContentModel1> >(mmodel2.Prop2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>(mmodel2.Prop2); PublishedSnapshotTestObjects.TestContentModel1 mmodel1 = mmodel2.Prop2.First(); // and we get what we want Assert.AreSame(cacheContent[mmodel1.Id], mmodel1); }