Exemplo n.º 1
0
        public void Int64ShouldBeNumericType()
        {
            var edmProperty     = this.builder.Build <long>("prop");
            var mappingProperty = new MappingProperty(edmProperty);

            mappingProperty.IsTypeOfNumericKey().Should().BeTrue();
        }
Exemplo n.º 2
0
        public void ConceptualVsStore()
        {
            var factory = new SampleGeneratorFactory(
                CodeFirstGen.OneToMany.Csdl(),
                CodeFirstGen.OneToMany.Ssdl(),
                CodeFirstGen.OneToMany.Msdl());

            // -- STORE ------------------------------
            var storeEntityType      = factory.StoreItemCollection.OfType <EntityType>().First(x => x.Name == "Tags");
            var storeMappingProperty = new MappingProperty(storeEntityType.Properties.First(x => x.Name == "ID"));

            var storeTestSubject = new MappingPropertyMatcherHasStoreGeneratedPattern(storeEntityType);

            storeTestSubject.IsMatch(storeMappingProperty).Should().BeFalse();

            // -- CONCEPTUAL ------------------------------
            var conceptualEntityType      = factory.ConceptualItemCollection.OfType <EntityType>().First(x => x.Name == "Tag");
            var conceptualMappingProperty = new MappingProperty(conceptualEntityType.Properties.First(x => x.Name == "ID"));

            var conceptualTestSubject = new MappingPropertyMatcherHasStoreGeneratedPattern(conceptualEntityType);

            conceptualTestSubject.IsMatch(conceptualMappingProperty).Should().BeTrue();
            conceptualTestSubject.GetStoreGeneratedPattern(conceptualMappingProperty).Should().Be(StoreGeneratedPattern.None);

            // NOTE: there's a difference!  Make sure it is crystal clear!!
            storeTestSubject.IsMatch(storeMappingProperty).Should().BeFalse();
            conceptualTestSubject.IsMatch(conceptualMappingProperty).Should().BeTrue();
        }
        public void IsRequiredTypeInt32ShouldReturnFalse()
        {
            var edmProperty     = this.builder.Build <int>("prop");
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsRequired();

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
Exemplo n.º 4
0
        public void IsFixedLength()
        {
            var edmProperty     = this.builder.BuildString("prop", false, true);
            var mappingProperty = new MappingProperty(edmProperty);

            mappingProperty.IsTypeOfString().Should().BeTrue();
            mappingProperty.HasFacet(DbProviderManifest.FixedLengthFacetName).Should().BeTrue();
            mappingProperty.GetFacetValue <bool>(DbProviderManifest.FixedLengthFacetName).Should().BeTrue();
        }
Exemplo n.º 5
0
        private T GetPropertyValue <T>(MappingProperty property, ref T field)
        {
            if (!this.propertiesSet[(int)property])
            {
                throw new InvalidOperationException(string.Format(Resources.Culture, Resources.MappingDestination_GetPropertyValue_PropertyNotSet, property));
            }

            return(field);
        }
Exemplo n.º 6
0
        public void IsRowVersionShouldReturnFalse()
        {
            var edmProperty     = this.builder.BuildBinary("prop", false, 8);
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsRowVersion();

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
Exemplo n.º 7
0
        public void UnboundedStringShouldNotHaveMaxLength()
        {
            var edmProperty     = this.builder.BuildString("prop", false, false);
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherMaxLength();

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
        public void IsUnicodeTypeStringShouldReturnFalse()
        {
            var edmProperty     = this.builder.BuildString("prop", false, false);
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsUnicode();

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
Exemplo n.º 9
0
        public void IsStoreGeneratedIdenittyPatternShouldBeTrue()
        {
            var edmProperty = this.builder.Build <int>("prop");

            edmProperty.StoreGeneratedPattern = System.Data.Entity.Core.Metadata.Edm.StoreGeneratedPattern.Identity;

            var mappingProperty = new MappingProperty(edmProperty);

            mappingProperty.IsStoreGeneratedIdentity.Should().BeTrue();
        }
Exemplo n.º 10
0
        public void MaxLengthStringShouldHaveMaxLength()
        {
            var edmProperty     = this.builder.BuildString("prop", false, false, 128);
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherMaxLength();

            testSubject.IsMatch(mappingProperty).Should().BeTrue();
            testSubject.GetMaxLength(mappingProperty).Should().Be(128);
        }
Exemplo n.º 11
0
        public void IsFixedLengthStringShouldBeFalse()
        {
            var edmProperty = this.builder
                              .BuildString("prop", false, false);

            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsFixedLength();

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
Exemplo n.º 12
0
        public void IsRowVersionShouldReturnTrue()
        {
            var edmProperty = this.builder.BuildBinary("prop", true, 8);

            edmProperty.StoreGeneratedPattern = StoreGeneratedPattern.Computed;

            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsRowVersion();

            testSubject.IsMatch(mappingProperty).Should().BeTrue();
        }
Exemplo n.º 13
0
        public void MaxLengthBinary()
        {
            var edmProperty     = this.builder.BuildBinary("prop", false, 100);
            var mappingProperty = new MappingProperty(edmProperty);

            mappingProperty.IsTypeOfByteArray().Should().BeTrue();
            mappingProperty.HasFacet(DbProviderManifest.FixedLengthFacetName).Should().BeTrue();
            mappingProperty.GetFacetValue <bool>(DbProviderManifest.FixedLengthFacetName).Should().BeFalse();

            mappingProperty.HasFacet(DbProviderManifest.MaxLengthFacetName).Should().BeTrue();
            mappingProperty.GetFacetValue <int>(DbProviderManifest.MaxLengthFacetName).Should().Be(100);
        }
        public void IsRequiredTypeStringShouldReturnTrue()
        {
            var edmProperty = this.builder
                              .BuildString("prop", false, false);

            edmProperty.Nullable = false;
            var mappingProperty = new MappingProperty(edmProperty);

            var testSubject = new MappingPropertyMatcherIsRequired();

            testSubject.IsMatch(mappingProperty).Should().BeTrue();
        }
Exemplo n.º 15
0
        public void Required()
        {
            var edmProperty = this.builder.BuildString("prop", false, false);

            edmProperty.Nullable = false;

            var mappingProperty = new MappingProperty(edmProperty);

            mappingProperty.IsNullable.Should().BeFalse();
            mappingProperty.GetClrEquivalentType().Should().Be(typeof(string));
            mappingProperty.IsTypeOfString().Should().BeTrue();
            mappingProperty.IsNullable.Should().BeFalse();
        }
Exemplo n.º 16
0
        public void NonKeyMemberWithIdentityShouldHaveStoreGeneratedIdentity()
        {
            var entityType = this.builder
                             .Name("My.Table")
                             .WithProperty <int>("ID", x => x.StoreGeneratedPattern = StoreGeneratedPattern.Identity)
                             .Build();

            var mappingProperty = new MappingProperty(entityType.Properties.Single());

            var testSubject = new MappingPropertyMatcherHasStoreGeneratedPattern(entityType);

            testSubject.IsMatch(mappingProperty).Should().BeTrue();
            testSubject.GetStoreGeneratedPattern(mappingProperty).Should().Be(StoreGeneratedPattern.Identity);
        }
Exemplo n.º 17
0
        public void NumericKeyShouldNotMatch()
        {
            var entityType = this.builder
                             .Name("My.Table")
                             .WithProperty <int>("ID", x => x.StoreGeneratedPattern = StoreGeneratedPattern.Identity)
                             .WithKeys("ID")
                             .Build();

            var mappingProperty = new MappingProperty(entityType.Properties.Single());

            var testSubject = new MappingPropertyMatcherHasStoreGeneratedPattern(entityType);

            testSubject.IsMatch(mappingProperty).Should().BeFalse();
        }
Exemplo n.º 18
0
        public vmUser Authenticate(string username, string password)
        {
            vmUser _user = new vmUser();
            var    user  = db.SecUsers.SingleOrDefault(x => x.UserName == username && x.Password == password);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            // JWT Implementation

            var ClaimData  = new[] { new Claim(ClaimTypes.Name, username), new Claim(ClaimTypes.Role, "admin") };
            var _key       = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_appSettings.Secret));
            var SignInCred = new SigningCredentials(_key, SecurityAlgorithms.HmacSha256Signature);

            var _token = new JwtSecurityToken(
                issuer: "localhost:5001",
                audience: "localhost:5001",
                expires: DateTime.Now.AddMinutes(5),
                claims: ClaimData,
                signingCredentials: SignInCred
                );

            var Token = new JwtSecurityTokenHandler().WriteToken(_token);

            user.Token         = Token; // tokenHandler.WriteToken(token);
            user.TokenExpireOn = DateTime.Now.AddMinutes(5);
            db.SecUsers.Update(user);
            db.SaveChanges();
            user.Password = null;
            MappingProperty.Map(_user, user);
            var userRoles           = db.SecUserRoles.Where(x => x.SecUserId == user.SecUserId).Select(x => x.SecRoleId).ToList();
            var userRolePermissions = db.SecRolePermissions.Where(x => userRoles.Contains(x.SecRoleId)).Select(x => x.SecPermissionId).ToList();
            var userPermissions     = db.SecPermissions.Where(x => userRolePermissions.Contains(x.SecPermissionId)).ToList();

            _user.permissions = userPermissions;
            _user.RoleName    = db.SecRoles.Where(x => x.SecRoleId == userRoles[0]).FirstOrDefault().RoleName;

            return(_user);
        }
Exemplo n.º 19
0
        public void CompositeKeyShouldHaveStoreGeneratedNone()
        {
            var entityType = this.builder
                             .Name("My.Table")
                             .WithProperty <int>("ID", x => x.StoreGeneratedPattern      = StoreGeneratedPattern.None)
                             .WithProperty <string>("Name", x => x.StoreGeneratedPattern = StoreGeneratedPattern.None)
                             .WithKeys("ID", "Name")
                             .Build();

            var testSubject = new MappingPropertyMatcherHasStoreGeneratedPattern(entityType);

            var mappingProperty1 = new MappingProperty(entityType.Properties.First(x => x.Name == "ID"));

            testSubject.IsMatch(mappingProperty1).Should().BeTrue();
            testSubject.GetStoreGeneratedPattern(mappingProperty1).Should().Be(StoreGeneratedPattern.None);

            var mappingProperty2 = new MappingProperty(entityType.Properties.First(x => x.Name == "Name"));

            testSubject.IsMatch(mappingProperty2).Should().BeFalse();
        }
Exemplo n.º 20
0
 public bool IsMatch(MappingProperty mappingProperty)
 {
     return
         ((mappingProperty.IsTypeOfString() || mappingProperty.IsTypeOfByteArray()) &&
          !mappingProperty.IsNullable);
 }
Exemplo n.º 21
0
 public bool IsPropertySet(MappingProperty property)
 {
     return(this.IsPropertySet((int)property));
 }
Exemplo n.º 22
0
 // ReSharper disable once RedundantAssignment
 private void SetPropertyValue <T>(MappingProperty property, T value, ref T field)
 {
     field = value;
     this.propertiesSet[(int)property] = true;
 }