Ejemplo n.º 1
0
        public void AreValidForReturnsFalseWhenExtensionListDoesNotMatchModelList()
        {
            // Setup
            const string Tenant     = "tenant";
            var          mockTenant = new Tenant {
                Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium
            };

            var list = new List <UDFItem> {
                new UDFItem {
                    DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display"
                }
            };
            var testModel = new TestExtension();

            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var result = udfDictionary.AreValidFor <TestExtension>(Tenant, list);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 2
0
        public void AddFieldsForReturnsErrorWhenDuplicateFieldIsAdded()
        {
            // Setup
            const string Tenant     = "tenant";
            var          mockTenant = new Mock <Tenant>();
            var          metadata   = new UDFMetadata {
                Name = "custom", Display = "custom"
            };
            var duplicateMetadata = new UDFMetadata {
                Name = "custom", Display = "custom"
            };
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            IEnumerable <UDFMetadataError> errors = new List <UDFMetadataError>();
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            udfDictionary.AddFieldFor <TestExtension>(Tenant, metadata, out errors);

            // Act
            var result = udfDictionary.AddFieldFor <TestExtension>(Tenant, duplicateMetadata, out errors);

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(errors.Count() > 0);
            Assert.IsTrue(errors.ToList()[0].Field == UDFMetadataField.Name);
        }
Ejemplo n.º 3
0
        public void GetFieldsForReturnsOneWhenFieldIsAdded()
        {
            // Setup
            const string Tenant = "tenant";

            var mockTenant = new Tenant {
                Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium
            };

            var metadata = new UDFMetadata {
                Name = "custom", Display = "display"
            };
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable <UDFMetadataError> errors = new List <UDFMetadataError>();
            var result = udfDictionary.AddFieldFor <TestExtension>(Tenant, metadata, out errors);

            // Act
            var fields = udfDictionary.GetFieldsFor <TestExtension>(Tenant);

            // Assert
            Assert.AreEqual(1, fields.Count());
        }
Ejemplo n.º 4
0
        public void AreValidForReturnsTrueWhenExtensionListMatchesModelList()
        {
            // Setup
            const string Tenant     = "tenant";
            var          mockTenant = new Tenant {
                Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium
            };

            var list = new List <UDFItem> {
                new UDFItem {
                    DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display"
                }
            };
            var testModel = new TestExtension();

            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var metadata = new UDFMetadata {
                Name = "custom", Display = "display"
            };

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable <UDFMetadataError> errors = new List <UDFMetadataError>();

            udfDictionary.AddFieldFor <TestExtension>(Tenant, metadata, out errors);

            // Act
            var result = udfDictionary.AreValidFor <TestExtension>(Tenant, list);

            // Assert
            Assert.IsTrue(result);
        }
Ejemplo n.º 5
0
        public void AddFieldsForReturnsTrue()
        {
            // Setup
            const string Tenant     = "tenant";
            var          mockTenant = new Mock <Tenant>();
            var          metadata   = new UDFMetadata {
                Name = "custom", Display = "display"
            };
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            // Act
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable <UDFMetadataError> errors = new List <UDFMetadataError>();

            var result = udfDictionary.AddFieldFor <TestExtension>(Tenant, metadata, out errors);

            // Assert
            Assert.IsTrue(result);
        }
Ejemplo n.º 6
0
        public void AddFieldsForReturnsErrorWhenEmptyFieldNameIsAdded()
        {
            // Setup
            const string Tenant = "tenant";
            var mockTenant = new Mock<Tenant>();
            var metadata = new UDFMetadata { Name = string.Empty, Display = "custom" };
            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(errors.Count() > 0);
            Assert.AreEqual(UDFMetadataField.Name, errors.ToList()[0].Field);
            Assert.AreEqual("Cannot be empty or 'new'", errors.ToList()[0].Message);
        }
Ejemplo n.º 7
0
        public void AddFieldsForReturnsErrorWhenDuplicateFieldIsAdded()
        {
            // Setup
            const string Tenant = "tenant";
            var mockTenant = new Mock<Tenant>();
            var metadata = new UDFMetadata { Name = "custom", Display = "custom" };
            var duplicateMetadata = new UDFMetadata { Name = "custom", Display = "custom" };
            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);

            // Act
            var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, duplicateMetadata, out errors);

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(errors.Count() > 0);
            Assert.IsTrue(errors.ToList()[0].Field == UDFMetadataField.Name);
        }
Ejemplo n.º 8
0
        public void AddFieldsForReturnsErrorWhenEmptyFieldNameIsAdded()
        {
            // Setup
            const string Tenant     = "tenant";
            var          mockTenant = new Mock <Tenant>();
            var          metadata   = new UDFMetadata {
                Name = string.Empty, Display = "custom"
            };
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            IEnumerable <UDFMetadataError> errors = new List <UDFMetadataError>();
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var result = udfDictionary.AddFieldFor <TestExtension>(Tenant, metadata, out errors);

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(errors.Count() > 0);
            Assert.AreEqual(UDFMetadataField.Name, errors.ToList()[0].Field);
            Assert.AreEqual("Cannot be empty or 'new'", errors.ToList()[0].Message);
        }
Ejemplo n.º 9
0
        public void GetFieldsForReturnsNullWhenEmptyList()
        {
            // Setup
            const string Tenant = "tenant";

            var mockTenant = new Tenant {
                Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium
            };

            var metadata = new UDFMetadata {
                Name = "custom", Display = "display"
            };
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var fields = udfDictionary.GetFieldsFor <TestExtension>(Tenant);

            // Assert
            Assert.IsNull(fields);
        }
Ejemplo n.º 10
0
        public void RemoveFieldForRemovesCustomField()
        {
            // Setup
            const string Tenant = "tenant";

            var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium };

            var metadata = new UDFMetadata { Name = "custom", Display = "display" };
            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();
            var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);
            var f1 = udfDictionary.GetFieldsFor<TestExtension>(Tenant);

            // Act
            udfDictionary.RemoveFieldFor<TestExtension>(Tenant, "custom");
            var fields = udfDictionary.GetFieldsFor<TestExtension>(Tenant);

            // Assert
            mockTenantStore.Verify(m => m.SaveTenant(mockTenant));
            Assert.AreEqual(0, fields.Count());
        }
Ejemplo n.º 11
0
        public void GetFieldsForReturnsNullWhenEmptyList()
        {
            // Setup
            const string Tenant = "tenant";

            var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium };

            var metadata = new UDFMetadata { Name = "custom", Display = "display" };
            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var fields = udfDictionary.GetFieldsFor<TestExtension>(Tenant);

            // Assert
            Assert.IsNull(fields);
        }
Ejemplo n.º 12
0
        public void AreValidForReturnsTrueWhenExtensionListMatchesModelList()
        {
            // Setup
            const string Tenant = "tenant";
            var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium };

            var list = new List<UDFItem> { new UDFItem { DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display" } };
            var testModel = new TestExtension();

            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var metadata = new UDFMetadata { Name = "custom", Display = "display" };

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();
            udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);

            // Act
            var result = udfDictionary.AreValidFor<TestExtension>(Tenant, list);

            // Assert
            Assert.IsTrue(result);
        }
Ejemplo n.º 13
0
        public void AreValidForReturnsFalseWhenExtensionListDoesNotMatchModelList()
        {
            // Setup
            const string Tenant = "tenant";
            var mockTenant = new Tenant { Name = Tenant, SubscriptionKind = Shared.Models.SubscriptionKind.Premium };

            var list = new List<UDFItem> { new UDFItem { DefaultValue = "defaultvalue", Name = "name", Value = "value", Display = "display" } };
            var testModel = new TestExtension();

            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant);

            var udfDictionary = new UDFDictionary(mockTenantStore.Object);

            // Act
            var result = udfDictionary.AreValidFor<TestExtension>(Tenant, list);

            // Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 14
0
        public void AddFieldsForReturnsTrue()
        {
            // Setup
            const string Tenant = "tenant";
            var mockTenant = new Mock<Tenant>();
            var metadata = new UDFMetadata { Name = "custom", Display = "display" };
            var mockTenantStore = new Mock<ITenantStore>();
            mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);

            // Act
            var udfDictionary = new UDFDictionary(mockTenantStore.Object);
            IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();

            var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);

            // Assert
            Assert.IsTrue(result);
        }