public void Should_check_for_uniqueness_by_specification() { var address = "*****@*****.**"; var otherAddress = "*****@*****.**"; var differentCase = "*****@*****.**"; var existing = new User {EmailAddress = address}; var incoming = new User {EmailAddress = otherAddress}; PersistEntities(existing); var counter = CreateEntityCounter(); //The only existing one is "me" var spec = new EntitySpecificationOfGuid<User>{PropertyExpression = x=> x.EmailAddress, Value = address, Id = existing.Id}; counter.CountByProperty(spec).ShouldEqual(0); //The existing user has this value var spec2 = new EntitySpecificationOfGuid<User>{PropertyExpression = x=> x.EmailAddress, Value = address, Id = incoming.Id}; counter.CountByProperty(spec2).ShouldEqual(1); //Case insensitive. A SQLServer installation configuration. var spec3 = new EntitySpecificationOfGuid<User> { PropertyExpression = x => x.EmailAddress, Value = differentCase, Id = incoming.Id }; counter.CountByProperty(spec3).ShouldEqual(1); //This email address is not in the database var spec4 = new EntitySpecificationOfGuid<User> { PropertyExpression = x => x.EmailAddress, Value = otherAddress, Id = incoming.Id }; counter.CountByProperty(spec4).ShouldEqual(0); }
public void Should_indicate_populated_id() { var spec = new EntitySpecificationOfGuid <User> { Id = Guid.NewGuid() }; spec.HasExistingId.ShouldBeTrue(); }
public void Should_indicate_empty_id() { var spec = new EntitySpecificationOfGuid<User>(); spec.HasExistingId.ShouldBeFalse(); spec.Id = Guid.Empty; spec.HasExistingId.ShouldBeFalse(); }
public void should_have_existing_id() { var id = Guid.NewGuid(); var spec = new EntitySpecificationOfGuid <User> { Id = id }; spec.ExistingId.ShouldEqual(id); }
public void Should_indicate_empty_id() { var spec = new EntitySpecificationOfGuid <User>(); spec.HasExistingId.ShouldBeFalse(); spec.Id = Guid.Empty; spec.HasExistingId.ShouldBeFalse(); }
protected override string IsValidCore(UpdateUserCommandMessage message) { var uniquenessSpecification = new EntitySpecificationOfGuid <User> { Value = message.Username, PropertyExpression = x => x.Username, Id = message.Id, }; var isUnique = _uniquenessChecker.IsUnique(uniquenessSpecification); return(isUnique ? Success() : _uniquenessChecker.BuildFailureMessage <User>(message.Username, x => x.Username)); }
public void should_indicate_failure_when_input_property_is_not_unique() { var specification = new EntitySpecificationOfGuid<TestModel>(); var counter = EntityCounterSpy<TestModel>.With().StubbedCount(1); var checker = new UniquenessChecker(counter); var result = checker.IsUnique(specification); result.ShouldBeFalse(); counter.Specification.ShouldBeTheSameAs(specification); }
public void should_indicate_success_when_input_has_a_unique_property() { var specification = new EntitySpecificationOfGuid<TestModel>(); var counter = EntityCounterSpy<TestModel>.With().StubbedCount(0); var checker = new UniquenessChecker(counter); var result = checker.IsUnique(specification); result.ShouldBeTrue(); counter.Specification.ShouldBeTheSameAs(specification); }
public void should_indicate_failure_when_input_property_is_not_unique() { var specification = new EntitySpecificationOfGuid <TestModel>(); var counter = EntityCounterSpy <TestModel> .With().StubbedCount(1); var checker = new UniquenessChecker(counter); var result = checker.IsUnique(specification); result.ShouldBeFalse(); counter.Specification.ShouldBeTheSameAs(specification); }
public void should_indicate_success_when_input_has_a_unique_property() { var specification = new EntitySpecificationOfGuid <TestModel>(); var counter = EntityCounterSpy <TestModel> .With().StubbedCount(0); var checker = new UniquenessChecker(counter); var result = checker.IsUnique(specification); result.ShouldBeTrue(); counter.Specification.ShouldBeTheSameAs(specification); }
public void Should_check_for_uniqueness_by_specification() { var address = "*****@*****.**"; var otherAddress = "*****@*****.**"; var differentCase = "*****@*****.**"; var existing = new User { EmailAddress = address }; var incoming = new User { EmailAddress = otherAddress }; PersistEntities(existing); var counter = CreateEntityCounter(); //The only existing one is "me" var spec = new EntitySpecificationOfGuid <User> { PropertyExpression = x => x.EmailAddress, Value = address, Id = existing.Id }; counter.CountByProperty(spec).ShouldEqual(0); //The existing user has this value var spec2 = new EntitySpecificationOfGuid <User> { PropertyExpression = x => x.EmailAddress, Value = address, Id = incoming.Id }; counter.CountByProperty(spec2).ShouldEqual(1); //Case insensitive. A SQLServer installation configuration. var spec3 = new EntitySpecificationOfGuid <User> { PropertyExpression = x => x.EmailAddress, Value = differentCase, Id = incoming.Id }; counter.CountByProperty(spec3).ShouldEqual(1); //This email address is not in the database var spec4 = new EntitySpecificationOfGuid <User> { PropertyExpression = x => x.EmailAddress, Value = otherAddress, Id = incoming.Id }; counter.CountByProperty(spec4).ShouldEqual(0); }
public void Should_indicate_populated_id() { var spec = new EntitySpecificationOfGuid<User>{Id = Guid.NewGuid()}; spec.HasExistingId.ShouldBeTrue(); }
public void should_have_existing_id() { var id = Guid.NewGuid(); var spec = new EntitySpecificationOfGuid<User> { Id = id }; spec.ExistingId.ShouldEqual(id); }