Beispiel #1
0
        public void AttributeBasedKeyFactoryBuilder_GivenModelWithoutKeyProperties_ShouldThrowException()
        {
            var builder   = new AttributeBasedKeyFactoryBuilder <KeyAttribute>();
            var exception = Assert.Throws <InvalidOperationException>(() => builder.BuildKeyFactory <UserWithoutKeyAttribute>());

            Assert.That(exception.Message, Is.EqualTo("Entity type UserWithoutKeyAttribute does not contain any property marked with KeyAttribute"));
        }
Beispiel #2
0
        public void AttributeBasedKeyFactoryBuilder_GivenModelWithOneKeyProperty_ShouldReturnCorrectKey()
        {
            var builder = new AttributeBasedKeyFactoryBuilder <KeyAttribute>();
            var factory = builder.BuildKeyFactory <User>();
            var userId  = Guid.NewGuid();
            var key     = factory(new User {
                Id = userId, FullName = "Jake Snake"
            }, null);

            Assert.That(key, Is.EqualTo(new Tuple <Guid>(userId)));
        }
Beispiel #3
0
        public void AttributeBasedKeyFactoryBuilder_GivenModelWithTwoKeyProperties_ShouldReturnCorrectKey()
        {
            var builder = new AttributeBasedKeyFactoryBuilder <KeyAttribute>();
            var factory = builder.BuildKeyFactory <TenantUser>();
            var userId  = Guid.NewGuid();
            var tenant  = Guid.NewGuid().ToString("N");
            var key     = factory(new TenantUser {
                Id = userId, Tenant = tenant, FullName = "Jake Snake"
            }, null);

            Assert.That(key, Is
                        .EqualTo(new Tuple <Guid, string>(userId, tenant))
                        .Or
                        .EqualTo(new Tuple <string, Guid>(tenant, userId)));
        }