예제 #1
0
        public void Unify_UnknownType()
        {
            var unifier = new TypeUnifier();
            var ts      = new FakeType();

            Assert.ThrowsException <NotSupportedException>(() => unifier.Unify(typeof(int), ts));
        }
예제 #2
0
        public void CreateResponseFromObject()
        {
            var stubbedData = new FakeType
            {
                SomeId   = 42,
                SomeData = "the meaning of life"
            };

            var response     = new EsiResponse <FakeType>(HttpStatusCode.OK, stubbedData);
            var httpResponse = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonSerializer.Serialize(stubbedData))
            };

            var result = _responseFactory.Create <FakeType>(httpResponse);

            if (!(result.Data is null))
            {
                Assert.AreEqual(response.Data !.SomeId, result.Data.SomeId);
                Assert.AreEqual(response.Data !.SomeData, result.Data.SomeData);

                Assert.IsNull(result.Error);
                Assert.IsNull(result.Message);
            }
예제 #3
0
        public void CreateFake(FakeType fakeType)
        {
            TripViewModel fake;

            if (fakeType == FakeType.Trip)
            {
                TripViewModel fakeTrip = this.Items.FirstOrDefault(p => p.Identifier == -1);
                if (fakeTrip != null)
                    this.Items.Remove(fakeTrip);

                fake = new TripViewModel()
                {
                    Identifier = -1,
                    Title = "New Trip?",
                    Description = "Click here to add a trip",
                    LocalPathImage = "Assets/NewTrip.png",
                };
            }
            else
            {
                fake = new TripViewModel()
                {
                    Identifier = -1,
                    Title = "Comming Soon",
                    Description = "We are working",
                    LocalPathImage = "Assets/Suggestion.png",
                    IsSuggestion = true,
                };
            }

            fake.ItemGroups.Clear();
            fake.ItemGroups = new ObservableCollection<CategoryViewModel>();
            this.Items.Add(fake);
        }
예제 #4
0
파일: Proof.cs 프로젝트: dbrgn/pi-vote
        /// <summary>
        /// Creates a new sum proof.
        /// </summary>
        /// <param name="r">The randomness used to encrypt the vote.</param>
        /// <param name="voteSum">The sum of all votes for which to generate a proof.</param>
        /// <param name="publicKey">The public key with which the vote was encrypted.</param>
        /// <param name="parameters">Cryptographic Parameters.</param>
        /// /// <param name="fakeType">What fake to create?</param>
        public Proof(BigInt r, Vote voteSum, BigInt publicKey, BaseParameters parameters, FakeType fakeType)
        {
            if (r == null)
            throw new ArgumentNullException("r");
              if (voteSum == null)
            throw new ArgumentNullException("vote");
              if (publicKey == null)
            throw new ArgumentNullException("publicKey");
              if (parameters == null)
            throw new ArgumentNullException("parameters");

              BigInt r0 = parameters.Random();
              MemoryStream serializeStream = new MemoryStream();
              SerializeContext serializer = new SerializeContext(serializeStream);
              SHA512Managed sha512 = new SHA512Managed();

              switch (fakeType)
              {
            case FakeType.BadFiatShamir:

              T0 = publicKey.PowerMod(r0, parameters.P);

              serializer.Write(voteSum.Ciphertext);
              serializer.Write(voteSum.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Close();
              serializeStream.Close();

              byte[] hash0 = sha512.ComputeHash(serializeStream.ToArray());
              C0 = 0;

              S0 = r0 + r * C0;

              break;

            case FakeType.BadPowerMod:

              T0 = publicKey.PowerMod(0, parameters.P);

              serializer.Write(voteSum.Ciphertext);
              serializer.Write(voteSum.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Close();
              serializeStream.Close();

              byte[] hash1 = sha512.ComputeHash(serializeStream.ToArray());
              C0 = hash1[0] | (hash1[1] << 8);

              S0 = 1;

              break;

            default:
              throw new NotSupportedException("Cannot generate that type of fake.");
              }
        }
            public void TrueSpecification_ReturnTrue <T>(FakeType candidate, Expression <Func <FakeType, T> > selector)
            {
                var specification = MockSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.True(result);
            }
        public virtual void Get_named_mappings_for_sql_type(string typeName, string udtName)
        {
            var type = new FakeType(typeName);

            var mapping = GetMapping(type);

            Assert.Equal(udtName, mapping.StoreType);
            Assert.Equal(udtName, ((SqlServerUdtTypeMapping)mapping).UdtTypeName);
            Assert.Same(type, mapping.ClrType);
        }
            public void InvokeTrueSpecification_ReturnTrue <T>(FakeType candidate,
                                                               Expression <Func <FakeType, T> > selector)
            {
                var specification = MockSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.True(result);
            }
예제 #8
0
            public void InvokeCastToInterfaceType_ReturnTrue()
            {
                var candidate     = new FakeType();
                var specification = MockSpecification <IEnumerable <char> > .True();

                var sut = new CastSpecification <FakeType, IEnumerable <char> >(specification);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.True(result);
            }
            public void FalseSpecification_ReturnFalse <T>(FakeType candidate, Expression <Func <FakeType, T> > selector)
            {
                candidate = candidate.Second != "null" ? candidate : null;
                var specification = MockSpecification <T> .False();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.False(result);
            }
            public void CastToInterfaceType_ReturnTrue()
            {
                var candidate     = new FakeType();
                var specification = MockSpecification <IEnumerable <char> > .True();

                var sut = new CastSpecification <FakeType, IEnumerable <char> >(specification);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.True(result);
            }
            public void TrueSpecification_ReturnExpectedResultObject <T>(FakeType candidate,
                                                                         Expression <Func <FakeType, T> > selector, SpecificationResult expected)
            {
                ISpecification <T> specification = MockValidationSpecification <T> .True();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var overall = sut.IsSatisfiedBy(candidate, out var result);

                Assert.True(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer());
            }
예제 #12
0
        private static TypeReference CreateTypeReference(FakeType fakeType)
        {
            if (fakeType == null)
            {
                return(null);
            }

            var monoCecilTypeReference = CreateMockFor <TypeReference>();

            monoCecilTypeReference.Setup(reference => reference.Name).Returns(() => fakeType.FullName.Split('.').Last());
            monoCecilTypeReference.Setup(reference => reference.FullName).Returns(() => fakeType.FullName);

            return(monoCecilTypeReference.Object);
        }
        private static MonoCecilTypeReference CreateMonoCecilTypeReference(FakeType fakeType)
        {
            if (fakeType == null)
            {
                return(null);
            }

            var monoCecilTypeReference = new Mock <MonoCecilTypeReference>(null);

            monoCecilTypeReference.Setup(reference => reference.Name).Returns(() => fakeType.Name);
            monoCecilTypeReference.Setup(reference => reference.FullName).Returns(() => fakeType.FullName);

            return(monoCecilTypeReference.Object);
        }
        public virtual void Get_named_mappings_for_sql_type(string typeName, string udtName)
        {
            var mapper = (IRelationalTypeMappingSource) new SqlServerTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

            var type = new FakeType(typeName);

            var mapping = mapper.FindMapping(type);

            Assert.Equal(udtName, mapping.StoreType);
            Assert.Equal(udtName, ((SqlServerUdtTypeMapping)mapping).UdtTypeName);
            Assert.Same(type, mapping.ClrType);
        }
            public void CastToInterfaceType_ReturnExpectedResultObject()
            {
                var candidate     = new FakeType();
                var specification = MockSpecification <IEnumerable <char> > .True();

                var expected = new SpecificationResult(2, true,
                                                       "CastSpecification<FakeType,IEnumerable<Char>>(TrueMockSpecification<IEnumerable<Char>>)");
                var sut = new CastSpecification <FakeType, IEnumerable <char> >(specification);

                var overall = sut.IsSatisfiedBy(candidate, out var result);

                Assert.True(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer());
            }
        private static ReflectionType CreateReflectionType(FakeType fakeType)
        {
            if (fakeType == null)
            {
                return(null);
            }

            var reflectionType = new Mock <ReflectionType>(fakeType.Type);

            reflectionType.Setup(reference => reference.Name).Returns(() => fakeType.Name);
            reflectionType.Setup(reference => reference.FullName).Returns(() => fakeType.FullName);

            return(reflectionType.Object);
        }
예제 #17
0
        public ComplexData()
        {
            AddValid(1)
            .Result("MockCommonSpecification<Int32>")
            .NegationResult("NotMockCommonSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(MockCommonSpecification <int>), "Match")
                            .Candidate(1));
            AddValid(1.5)
            .Result("MockCommonSpecification<Double>")
            .NegationResult("NotMockCommonSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(MockCommonSpecification <double>), "Match")
                            .Candidate(1.5));
            AddValid(true)
            .Result("MockCommonSpecification<Boolean>")
            .NegationResult("NotMockCommonSpecification<Boolean>+Failed", c => c
                            .FailedSpecification(typeof(MockCommonSpecification <bool>), "Match")
                            .Candidate(true));
            AddValid(BindingFlags.NonPublic)
            .Result("MockCommonSpecification<BindingFlags>")
            .NegationResult("NotMockCommonSpecification<BindingFlags>+Failed", c => c
                            .FailedSpecification(typeof(MockCommonSpecification <BindingFlags>), "Match")
                            .Candidate(BindingFlags.NonPublic));

            var obj  = new object();
            var list = new List <int>();
            var fake = new FakeType();

            AddInvalid(obj)
            .Result("MockCommonSpecification<Object>+Failed", c => c
                    .FailedSpecification(typeof(MockCommonSpecification <object>), "Not match")
                    .Candidate(obj))
            .NegationResult("NotMockCommonSpecification<Object>");
            AddInvalid(list)
            .Result("MockCommonSpecification<List<Int32>>+Failed", c => c
                    .FailedSpecification(typeof(MockCommonSpecification <List <int> >), "Not match")
                    .Candidate(list))
            .NegationResult("NotMockCommonSpecification<List<Int32>>");
            AddInvalid(fake)
            .Result("MockCommonSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(MockCommonSpecification <FakeType>), "Not match")
                    .Candidate(fake))
            .NegationResult("NotMockCommonSpecification<FakeType>");
            AddInvalid("")
            .Result("MockCommonSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(MockCommonSpecification <string>), "Not match")
                    .Candidate(""))
            .NegationResult("NotMockCommonSpecification<String>");
        }
            public void FalseSpecification_ReturnExpectedResultObject <T>(FakeType candidate,
                                                                          Expression <Func <FakeType, T> > selector, SpecificationResult expected)
            {
                candidate = candidate.Second != "null" ? candidate : null;
                ISpecification <T> specification = MockComplexSpecification <T> .False();

                var sut = new PropertySpecification <FakeType, T>(selector, specification);

                var overall = sut.IsSatisfiedBy(candidate, out var result);

                Assert.False(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer(
                                 parameters: new Dictionary <string, object>
                {
                    { "PropertySpecification", specification }
                }));
            }
        private void PutParameterDescriptions(MethodInfo methodInfo, IList <ApiParameterDescription> apiParameters)
        {
            if (!methodInfo.GetParameters().Any())
            {
                return;
            }

            Type argumentType = new FakeType(methodInfo);

            apiParameters.Add(new ApiParameterDescription
            {
                Name          = "Arguments",
                Type          = argumentType,
                ModelMetadata = new RequestTypeMetadata(argumentType, methodInfo.GetParameters().Select(x => new ParameterMetadata(x))),
                Source        = BindingSource.Body
            });
        }
예제 #20
0
        public PropertyExpressionData()
        {
            var candidate = new FakeType
            {
                First  = 1,
                Second = "2",
                Inter  = new InterFakeType()
            };
            var empty            = new FakeType();
            var ftSecondSelector = (Expression <Func <FakeType, string> >)(ft => ft.Second);
            var ftThirdSelector  = (Expression <Func <FakeType, bool> >)(ft => ft.Inter.Third);

            AddValid(candidate, ftSecondSelector);
            AddValid(candidate, ftThirdSelector);
            AddValid(empty, ftSecondSelector);

            AddInvalid(candidate, ftSecondSelector);
            AddInvalid(candidate, ftThirdSelector);
        }
예제 #21
0
파일: Vote.cs 프로젝트: dbrgn/pi-vote
        /// <summary>
        /// Creates a new encrypted vote with an invalid proof.
        /// </summary>
        /// <remarks>
        /// Includes invalid zero-knowledge proves of vote being 0 or 1 when it is not.
        /// </remarks>
        /// <param name="votum">Actual vote.</param>
        /// <param name="parameters">Cryptographic parameters.</param>
        /// <param name="publicKey">Public key of the authorities.</param>
        /// <param name="fakeType">What kind of a fake?</param>
        public Vote(int votum, BigInt nonce, BaseParameters parameters, BigInt publicKey, FakeType fakeType)
        {
            if (votum.InRange(0, 1))
            throw new ArgumentException("Cannot create a invalid proof of a valid votum.");
              if (nonce == null)
            throw new ArgumentNullException("nonce");
              if (parameters == null)
            throw new ArgumentNullException("parameters");
              if (publicKey == null)
            throw new ArgumentNullException("publicKey");

              P = parameters.P;
              HalfKey = parameters.G.PowerMod(nonce, P);

              //The 12 magic number is inserted to avoid division remainders when
              //dividing partial deciphers for linear combinations by 2, 3 and 4.
              Ciphertext = (publicKey.PowerMod(nonce * 12, P) * parameters.F.PowerMod(votum, P)).Mod(P);

              RangeProves = new List<RangeProof>();
              for (int proofIndex = 0; proofIndex < parameters.ProofCount; proofIndex++)
              {
            RangeProves.Add(new RangeProof(votum, nonce * 12, this, publicKey, parameters, fakeType));
              }
        }
예제 #22
0
 public FakeCommonTypeBuilder AddProperty(string name, FakeType propertyType, PropertyMethods propertyMethods, params Attribute[] propertyAttributes)
 {
     return(AddProperty(name, propertyType, propertyMethods, propertyAttributes.Select(attribute => new FakeAttribute(attribute)).ToArray()));
 }
 public CannotBeActivatedController(FakeType service)
 {
 }
예제 #24
0
파일: RangeProof.cs 프로젝트: dbrgn/pi-vote
        /// <summary>
        /// Creates a new invalid range proof.
        /// </summary>
        /// <remarks>
        /// Used to test proofing mechanism.
        /// </remarks>
        /// <param name="votum">The votum. Must NOT be 0 or 1.</param>
        /// <param name="r">The randomness used to encrypt the vote.</param>
        /// <param name="vote">The vote for which to generate a proof.</param>
        /// <param name="publicKey">The public key with which the vote was encrypted.</param>
        /// <param name="parameters">Cryptographic Parameters.</param>
        /// <param name="fakeType">What is to be wrong?</param>
        public RangeProof(int votum, BigInt r, Vote vote, BigInt publicKey, BaseParameters parameters, FakeType fakeType)
        {
            if (r == null)
            throw new ArgumentNullException("r");
              if (vote == null)
            throw new ArgumentNullException("vote");
              if (publicKey == null)
            throw new ArgumentNullException("publicKey");
              if (parameters == null)
            throw new ArgumentNullException("parameters");

              BigInt r0 = parameters.Random();
              BigInt r1 = parameters.Random();
              MemoryStream serializeStream = new MemoryStream();
              SerializeContext serializer = new SerializeContext(serializeStream);
              SHA512Managed sha512 = new SHA512Managed();

              switch (fakeType)
              {
            case FakeType.BadDisjunction:
              //The C value will not be correct as it is not considered.

              //Create the fake proof.
              C0 = (int)Prime.RandomNumber(16);
              S0 = parameters.Random();
              T0 = (vote.Ciphertext.DivideMod(parameters.F.PowerMod(0, parameters.P), parameters.P).PowerMod(C0, parameters.P).InvertMod(parameters.P) * publicKey.PowerMod(S0, parameters.P)).Mod(parameters.P);

              //Create the fake proof.
              C1 = (int)Prime.RandomNumber(16);
              S1 = parameters.Random();
              T1 = (vote.Ciphertext.DivideMod(parameters.F.PowerMod(1, parameters.P), parameters.P).PowerMod(C1, parameters.P).InvertMod(parameters.P) * publicKey.PowerMod(S1, parameters.P)).Mod(parameters.P);

              //Put togeather the data to be hashed.
              serializer.Write(vote.Ciphertext);
              serializer.Write(vote.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Write(T1);
              serializer.Close();
              serializeStream.Close();

              //Hash the proof data.
              byte[] hash0 = sha512.ComputeHash(serializeStream.ToArray());
              //Take the first 16 bits.
              C = hash0[0] | (hash0[1] << 8);

              break;

            case FakeType.BadFiatShamir:
              //The C value will not correspond to the hash.

              //Create the fake proof.
              C0 = (int)Prime.RandomNumber(16);
              S0 = parameters.Random();
              T0 = (vote.Ciphertext.DivideMod(parameters.F.PowerMod(0, parameters.P), parameters.P).PowerMod(C0, parameters.P).InvertMod(parameters.P) * publicKey.PowerMod(S0, parameters.P)).Mod(parameters.P);

              //Create the fake proof.
              C1 = (int)Prime.RandomNumber(16);
              S1 = parameters.Random();
              T1 = (vote.Ciphertext.DivideMod(parameters.F.PowerMod(1, parameters.P), parameters.P).PowerMod(C1, parameters.P).InvertMod(parameters.P) * publicKey.PowerMod(S1, parameters.P)).Mod(parameters.P);

              //Put togeather the data to be hashed.
              serializer.Write(vote.Ciphertext);
              serializer.Write(vote.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Write(T1);
              serializer.Close();
              serializeStream.Close();

              //Hash the proof data.
              byte[] hash1 = sha512.ComputeHash(serializeStream.ToArray());
              //Take the first 16 bits.
              C = C0 + C1;

              break;

            case FakeType.BadPowerMod:

              //Create the fake proof.
              C1 = (int)Prime.RandomNumber(16);
              S1 = parameters.Random();
              T1 = (vote.Ciphertext.DivideMod(parameters.F.PowerMod(1, parameters.P), parameters.P).PowerMod(C1, parameters.P).InvertMod(parameters.P) * publicKey.PowerMod(S1, parameters.P)).Mod(parameters.P);

              //First part of the real proof
              T0 = publicKey.PowerMod(r0, parameters.P);

              //Put togeather the data to be hashed.
              serializer.Write(vote.Ciphertext);
              serializer.Write(vote.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Write(T1);
              serializer.Close();
              serializeStream.Close();

              //Hash the proof data.
              byte[] hash2 = sha512.ComputeHash(serializeStream.ToArray());
              //Take the first 16 bits.
              C = hash2[0] | (hash2[1] << 8);

              //Second part of the real proof
              C0 = (int)((BigInt)(C - C1)).Mod(0xffff);
              S0 = r0 + r * C0;

              break;

            default:
              throw new NotSupportedException("Cannot fake in that way.");
              }
        }
예제 #25
0
 public FakeCommonTypeBuilder AddMethod(string name, FakeType returnType, FakeParameter[] parameters)
 {
     return(AddMethod(name, returnType, parameters, (FakeAttribute[])null));
 }
예제 #26
0
 public FakeCommonTypeBuilder AddField(string name, FakeType fieldType, params FakeAttribute[] fieldFakeAttributes)
 {
     fields.Add(new FakeField(name, fieldType, fieldFakeAttributes));
     return(this);
 }
예제 #27
0
 public CannotBeActivatedComponent(FakeType fakeType)
 {
 }
예제 #28
0
 public FakeCommonTypeBuilder AddMethod(string name, FakeType returnType, FakeParameter[] parameters, params Attribute[] methodAttributes)
 {
     return(AddMethod(name, returnType, parameters, methodAttributes.Select(attribute => new FakeAttribute(attribute)).ToArray()));
 }
예제 #29
0
 public FakeCommonTypeBuilder AddMethod(string name, FakeType returnType, FakeParameter[] parameters, params FakeAttribute[] methodFakeAttributes)
 {
     methods.Add(new FakeMethod(name, returnType, parameters, methodFakeAttributes));
     return(this);
 }
        public ExclusiveBetweenData()
        {
            var comparer           = new FakeTypeComparer();
            var intComparer        = new FakeIntComparer();
            ComparableFakeType cmp = new ComparableFakeType {
                First = 15
            },
                               cmpFrom = new ComparableFakeType {
                First = 1
            },
                               cmpTo = new ComparableFakeType {
                First = 30
            };
            FakeType cmpFakeType = new FakeType {
                First = 15
            },
                     cmpFromFakeType = new FakeType {
                First = 1
            },
                     cmpToFakeType = new FakeType {
                First = 30
            };

            AddValid(1, 0, 5, null)
            .Result("ExclusiveBetweenSpecification<Int32>")
            .NegationResult("NotExclusiveBetweenSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>), "Value is between [0] and [5]")
                            .Candidate(1)
                            .AddParameter("From", 0)
                            .AddParameter("To", 5));
            AddValid(-1, -5, 1, null)
            .Result("ExclusiveBetweenSpecification<Int32>")
            .NegationResult("NotExclusiveBetweenSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>), "Value is between [-5] and [1]")
                            .Candidate(-1)
                            .AddParameter("From", -5)
                            .AddParameter("To", 1));
            AddValid(-9, -24, -1, intComparer)
            .Result("ExclusiveBetweenSpecification<Int32>")
            .NegationResult("NotExclusiveBetweenSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>), "Value is between [-24] and [-1]")
                            .Candidate(-9)
                            .AddParameter("From", -24)
                            .AddParameter("To", -1));
            AddValid(5.74, 5.73, 5.75, null)
            .Result("ExclusiveBetweenSpecification<Double>")
            .NegationResult("NotExclusiveBetweenSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                                 "Value is between [5.73] and [5.75]")
                            .Candidate(5.74)
                            .AddParameter("From", 5.73)
                            .AddParameter("To", 5.75));
            AddValid(-2.5, -3.0, 0.0, null)
            .Result("ExclusiveBetweenSpecification<Double>")
            .NegationResult("NotExclusiveBetweenSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>), "Value is between [-3] and [0]")
                            .Candidate(-2.5)
                            .AddParameter("From", -3.0)
                            .AddParameter("To", 0.0));
            AddValid(-5.75, -5.76, -5.74, null)
            .Result("ExclusiveBetweenSpecification<Double>")
            .NegationResult("NotExclusiveBetweenSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                                 "Value is between [-5.76] and [-5.74]")
                            .Candidate(-5.75)
                            .AddParameter("From", -5.76)
                            .AddParameter("To", -5.74));
            AddValid("123", "122", "124", null)
            .Result("ExclusiveBetweenSpecification<String>")
            .NegationResult("NotExclusiveBetweenSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                                 "Value is between [122] and [124]")
                            .Candidate("123")
                            .AddParameter("From", "122")
                            .AddParameter("To", "124"));
            AddValid("123", "12", "1234", null)
            .Result("ExclusiveBetweenSpecification<String>")
            .NegationResult("NotExclusiveBetweenSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                                 "Value is between [12] and [1234]")
                            .Candidate("123")
                            .AddParameter("From", "12")
                            .AddParameter("To", "1234"));
            AddValid("test", null, "test1", null)
            .Result("ExclusiveBetweenSpecification<String>")
            .NegationResult("NotExclusiveBetweenSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                                 "Value is between [null] and [test1]")
                            .Candidate("test")
                            .AddParameter("From", null)
                            .AddParameter("To", "test1"));
            AddValid(DateTime.Parse("2018-01-15"), DateTime.Parse("2017-05-16"), DateTime.Parse("2019-07-11"), null)
            .Result("ExclusiveBetweenSpecification<DateTime>")
            .NegationResult("NotExclusiveBetweenSpecification<DateTime>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <DateTime>),
                                                 $"Value is between \\[{DateTimeRegexPattern}\\] and \\[{DateTimeRegexPattern}\\]")
                            .Candidate(DateTime.Parse("2018-01-15"))
                            .AddParameter("From", DateTime.Parse("2017-05-16"))
                            .AddParameter("To", DateTime.Parse("2019-07-11")));
            AddValid(DateTime.Parse("2019-07-05"), DateTime.Parse("2019-07-01"), DateTime.Parse("2019-07-11"), null)
            .Result("ExclusiveBetweenSpecification<DateTime>")
            .NegationResult("NotExclusiveBetweenSpecification<DateTime>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <DateTime>),
                                                 $"Value is between \\[{DateTimeRegexPattern}\\] and \\[{DateTimeRegexPattern}\\]")
                            .Candidate(DateTime.Parse("2019-07-05"))
                            .AddParameter("From", DateTime.Parse("2019-07-01"))
                            .AddParameter("To", DateTime.Parse("2019-07-11")));
            AddValid(cmp, cmpFrom, cmpTo, null)
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>")
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                                 "Value is between [Fake(1)] and [Fake(30)]")
                            .Candidate(cmp)
                            .AddParameter("From", cmpFrom)
                            .AddParameter("To", cmpTo));
            AddValid(cmp, null, cmpTo, null)
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>")
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                                 "Value is between [null] and [Fake(30)]")
                            .Candidate(cmp)
                            .AddParameter("From", null)
                            .AddParameter("To", cmpTo));
            AddValid(cmpFakeType, cmpFromFakeType, cmpToFakeType, comparer)
            .Result("ExclusiveBetweenSpecification<FakeType>")
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                                 "Value is between [Fake(1)] and [Fake(30)]")
                            .Candidate(cmpFakeType)
                            .AddParameter("From", cmpFromFakeType)
                            .AddParameter("To", cmpToFakeType));
            AddValid(cmpFakeType, null, cmpToFakeType, comparer)
            .Result("ExclusiveBetweenSpecification<FakeType>")
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>+Failed", c => c
                            .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                                 "Value is between [null] and [Fake(30)]")
                            .Candidate(cmpFakeType)
                            .AddParameter("From", null)
                            .AddParameter("To", cmpToFakeType));

            ComparableFakeType notCmp1 = new ComparableFakeType {
                First = 10
            },
                               notCmp2 = new ComparableFakeType {
                First = 15
            },
                               notCmp3 = new ComparableFakeType {
                First = 1
            },
                               notCmp4 = new ComparableFakeType {
                First = 3
            },
                               notCmp5 = new ComparableFakeType {
                First = 23
            },
                               notCmp6 = new ComparableFakeType {
                First = 30
            };
            ComparableInterFakeType cmpInter1 = new ComparableInterFakeType(),
                                    cmpInter2 = new ComparableInterFakeType(),
                                    cmpInter3 = new ComparableInterFakeType {
                Third = true
            };
            FakeType notCmpFakeType1 = new FakeType {
                First = 10
            },
                     notCmpFakeType2 = new FakeType {
                First = 15
            },
                     notCmpFakeType3 = new FakeType {
                First = 1
            },
                     notCmpFakeType4 = new FakeType {
                First = 3
            },
                     notCmpFakeType5 = new FakeType {
                First = 23
            },
                     notCmpFakeType6 = new FakeType {
                First = 30
            };

            AddInvalid(2, 2, 3, null)
            .NegationResult("NotExclusiveBetweenSpecification<Int32>")
            .Result("ExclusiveBetweenSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>), "Value is not between [2] and [3]")
                    .Candidate(2)
                    .AddParameter("From", 2)
                    .AddParameter("To", 3));
            AddInvalid(-2, -3, -2, null)
            .NegationResult("NotExclusiveBetweenSpecification<Int32>")
            .Result("ExclusiveBetweenSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>),
                                         "Value is not between [-3] and [-2]")
                    .Candidate(-2)
                    .AddParameter("From", -3)
                    .AddParameter("To", -2));
            AddInvalid(1, -3, -1, null)
            .NegationResult("NotExclusiveBetweenSpecification<Int32>")
            .Result("ExclusiveBetweenSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>),
                                         "Value is not between [-3] and [-1]")
                    .Candidate(1)
                    .AddParameter("From", -3)
                    .AddParameter("To", -1));
            AddInvalid(5, 1, 3, null)
            .NegationResult("NotExclusiveBetweenSpecification<Int32>")
            .Result("ExclusiveBetweenSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>), "Value is not between [1] and [3]")
                    .Candidate(5)
                    .AddParameter("From", 1)
                    .AddParameter("To", 3));
            AddInvalid(-1, -10, -5, intComparer)
            .NegationResult("NotExclusiveBetweenSpecification<Int32>")
            .Result("ExclusiveBetweenSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <int>),
                                         "Value is not between [-10] and [-5]")
                    .Candidate(-1)
                    .AddParameter("From", -10)
                    .AddParameter("To", -5));
            AddInvalid(3.5, 3.5, 3.5, null)
            .NegationResult("NotExclusiveBetweenSpecification<Double>")
            .Result("ExclusiveBetweenSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                         "Value is not between [3.5] and [3.5]")
                    .Candidate(3.5)
                    .AddParameter("From", 3.5)
                    .AddParameter("To", 3.5));
            AddInvalid(-3.5, -3.5, -3.5, null)
            .NegationResult("NotExclusiveBetweenSpecification<Double>")
            .Result("ExclusiveBetweenSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                         "Value is not between [-3.5] and [-3.5]")
                    .Candidate(-3.5)
                    .AddParameter("From", -3.5)
                    .AddParameter("To", -3.5));
            AddInvalid(5.74, 2.74, 3.74, null)
            .NegationResult("NotExclusiveBetweenSpecification<Double>")
            .Result("ExclusiveBetweenSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                         "Value is not between [2.74] and [3.74]")
                    .Candidate(5.74)
                    .AddParameter("From", 2.74)
                    .AddParameter("To", 3.74));
            AddInvalid(-3.74, -7.74, -5.74, null)
            .NegationResult("NotExclusiveBetweenSpecification<Double>")
            .Result("ExclusiveBetweenSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                         "Value is not between [-7.74] and [-5.74]")
                    .Candidate(-3.74)
                    .AddParameter("From", -7.74)
                    .AddParameter("To", -5.74));
            AddInvalid(5.74, -3.74, 5.73, null)
            .NegationResult("NotExclusiveBetweenSpecification<Double>")
            .Result("ExclusiveBetweenSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <double>),
                                         "Value is not between [-3.74] and [5.73]")
                    .Candidate(5.74)
                    .AddParameter("From", -3.74)
                    .AddParameter("To", 5.73));
            AddInvalid(false, false, true, null)
            .NegationResult("NotExclusiveBetweenSpecification<Boolean>")
            .Result("ExclusiveBetweenSpecification<Boolean>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <bool>),
                                         "Value is not between [False] and [True]")
                    .Candidate(false)
                    .AddParameter("From", false)
                    .AddParameter("To", true));
            AddInvalid("123", "121", "122", null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [121] and [122]")
                    .Candidate("123")
                    .AddParameter("From", "121")
                    .AddParameter("To", "122"));
            AddInvalid("1234", "122", "1233", null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [122] and [1233]")
                    .Candidate("1234")
                    .AddParameter("From", "122")
                    .AddParameter("To", "1233"));
            AddInvalid("123", "123", "124", null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [123] and [124]")
                    .Candidate("123")
                    .AddParameter("From", "123")
                    .AddParameter("To", "124"));
            AddInvalid("null", "test", "test1", null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [test] and [test1]")
                    .Candidate(null)
                    .AddParameter("From", "test")
                    .AddParameter("To", "test1"));
            AddInvalid("null", null, "test", null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [null] and [test]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", "test"));
            AddInvalid("null", null, null, null)
            .NegationResult("NotExclusiveBetweenSpecification<String>")
            .Result("ExclusiveBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <string>),
                                         "Value is not between [null] and [null]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", null));
            AddInvalid(DateTime.Parse("2019-11-15"), DateTime.Parse("2019-07-11"), DateTime.Parse("2019-11-15"), null)
            .NegationResult("NotExclusiveBetweenSpecification<DateTime>")
            .Result("ExclusiveBetweenSpecification<DateTime>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <DateTime>),
                                         $"Value is not between \\[{DateTimeRegexPattern}\\] and \\[{DateTimeRegexPattern}\\]")
                    .Candidate(DateTime.Parse("2019-11-15"))
                    .AddParameter("From", DateTime.Parse("2019-07-11"))
                    .AddParameter("To", DateTime.Parse("2019-11-15")));
            AddInvalid(DateTime.Parse("2019-11-15"), DateTime.Parse("2019-12-11"), DateTime.Parse("2019-12-15"), null)
            .NegationResult("NotExclusiveBetweenSpecification<DateTime>")
            .Result("ExclusiveBetweenSpecification<DateTime>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <DateTime>),
                                         $"Value is not between \\[{DateTimeRegexPattern}\\] and \\[{DateTimeRegexPattern}\\]")
                    .Candidate(DateTime.Parse("2019-11-15"))
                    .AddParameter("From", DateTime.Parse("2019-12-11"))
                    .AddParameter("To", DateTime.Parse("2019-12-15")));
            AddInvalid(cmp, notCmp1, notCmp2, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [Fake(10)] and [Fake(15)]")
                    .Candidate(cmp)
                    .AddParameter("From", notCmp1)
                    .AddParameter("To", notCmp2));
            AddInvalid(cmp, notCmp3, notCmp4, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [Fake(1)] and [Fake(3)]")
                    .Candidate(cmp)
                    .AddParameter("From", notCmp3)
                    .AddParameter("To", notCmp4));
            AddInvalid(cmp, notCmp5, notCmp6, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [Fake(23)] and [Fake(30)]")
                    .Candidate(cmp)
                    .AddParameter("From", notCmp5)
                    .AddParameter("To", notCmp6));
            AddInvalid(cmpInter1, cmpInter2, cmpInter3, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableInterFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableInterFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableInterFakeType>),
                                         "Value is not between [FluentSpecification.Tests.Mocks.ComparableInterFakeType] and [FluentSpecification.Tests.Mocks.ComparableInterFakeType]")
                    .Candidate(cmpInter1)
                    .AddParameter("From", cmpInter2)
                    .AddParameter("To", cmpInter3));
            AddInvalid(new ComparableFakeType {
                Second = "null"
            }, notCmp1, notCmp2, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [Fake(10)] and [Fake(15)]")
                    .Candidate(null)
                    .AddParameter("From", notCmp1)
                    .AddParameter("To", notCmp2));
            AddInvalid(new ComparableFakeType {
                Second = "null"
            }, null, notCmp2, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [null] and [Fake(15)]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", notCmp2));
            AddInvalid(new ComparableFakeType {
                Second = "null"
            }, null, null, null)
            .NegationResult("NotExclusiveBetweenSpecification<ComparableFakeType>")
            .Result("ExclusiveBetweenSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <ComparableFakeType>),
                                         "Value is not between [null] and [null]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", null));
            AddInvalid(cmpFakeType, notCmpFakeType1, notCmpFakeType2, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [Fake(10)] and [Fake(15)]")
                    .Candidate(cmpFakeType)
                    .AddParameter("From", notCmpFakeType1)
                    .AddParameter("To", notCmpFakeType2));
            AddInvalid(cmpFakeType, notCmpFakeType3, notCmpFakeType4, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [Fake(1)] and [Fake(3)]")
                    .Candidate(cmpFakeType)
                    .AddParameter("From", notCmpFakeType3)
                    .AddParameter("To", notCmpFakeType4));
            AddInvalid(cmpFakeType, notCmpFakeType5, notCmpFakeType6, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [Fake(23)] and [Fake(30)]")
                    .Candidate(cmpFakeType)
                    .AddParameter("From", notCmpFakeType5)
                    .AddParameter("To", notCmpFakeType6));
            AddInvalid(new FakeType {
                Second = "null"
            }, notCmpFakeType1, notCmpFakeType2, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [Fake(10)] and [Fake(15)]")
                    .Candidate(null)
                    .AddParameter("From", notCmpFakeType1)
                    .AddParameter("To", notCmpFakeType2));
            AddInvalid(new FakeType {
                Second = "null"
            }, null, notCmpFakeType2, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [null] and [Fake(15)]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", notCmpFakeType2));
            AddInvalid(new FakeType {
                Second = "null"
            }, null, null, comparer)
            .NegationResult("NotExclusiveBetweenSpecification<FakeType>")
            .Result("ExclusiveBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(ExclusiveBetweenSpecification <FakeType>),
                                         "Value is not between [null] and [null]")
                    .Candidate(null)
                    .AddParameter("From", null)
                    .AddParameter("To", null));
        }
예제 #31
0
        public AllData()
        {
            int[] arr  = { 1, 5, 200, 6, 100 };
            var   list = new List <string> {
                "First", "Second"
            };
            var dict = new Dictionary <string, bool> {
                { "First", true }, { "Second", false }
            };
            var ft = new FakeType {
                Fourth = arr
            };
            var empty  = new FakeType();
            var nullFt = new FakeType {
                Second = "null"
            };

            AddValid(arr, True <int>())
            .Result(6,
                    "AllSpecification<Int32[],Int32>([0](MockComplexSpecification[Int32]) And [1](MockComplexSpecification[Int32]) And [2](MockComplexSpecification[Int32]) And [3](MockComplexSpecification[Int32]) And [4](MockComplexSpecification[Int32]))");
            AddValid(list, True <string>())
            .Result(3,
                    "AllSpecification<List<String>,String>([0](MockComplexSpecification[String]) And [1](MockComplexSpecification[String]))");
            AddValid(dict, True <KeyValuePair <string, bool> >())
            .Result(3,
                    "AllSpecification<Dictionary<String,Boolean>,KeyValuePair<String,Boolean>>([0](MockComplexSpecification[KeyValuePair<String,Boolean>]) And [1](MockComplexSpecification[KeyValuePair<String,Boolean>]))");
            AddValid(ft, True <int>())
            .Result(6,
                    "AllSpecification<FakeType,Int32>([0](MockComplexSpecification[Int32]) And [1](MockComplexSpecification[Int32]) And [2](MockComplexSpecification[Int32]) And [3](MockComplexSpecification[Int32]) And [4](MockComplexSpecification[Int32]))");
            AddValid(empty, True <int>())
            .Result(1, "AllSpecification<FakeType,Int32>()");

            AddInvalid(nullFt, True <int>())
            .Result(1, "AllSpecification<FakeType,Int32>()+Failed", c => c
                    .FailedSpecification(typeof(AllSpecification <FakeType, int>), "Collection is null")
                    .Candidate(null)
                    .AddParameter("SpecificationForAll", null));
            AddInvalid(arr, False <int>())
            .Result(6,
                    "AllSpecification<Int32[],Int32>([0](FailedMockComplexSpecification[Int32]) And [1](FailedMockComplexSpecification[Int32]) And [2](FailedMockComplexSpecification[Int32]) And [3](FailedMockComplexSpecification[Int32]) And [4](FailedMockComplexSpecification[Int32]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <int[], int>),
                                      "One or more elements are not specified")
                .Candidate(arr)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[0] MockComplexSpecification is not satisfied")
                .Candidate(1)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate(5)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[2] MockComplexSpecification is not satisfied")
                .Candidate(200)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[3] MockComplexSpecification is not satisfied")
                .Candidate(6)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[4] MockComplexSpecification is not satisfied")
                .Candidate(100)
                .AddParameter("Expression", null);
            });
            AddInvalid(list, False <string>())
            .Result(3,
                    "AllSpecification<List<String>,String>([0](FailedMockComplexSpecification[String]) And [1](FailedMockComplexSpecification[String]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <List <string>, string>),
                                      "One or more elements are not specified")
                .Candidate(list)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <string>),
                                      "[0] MockComplexSpecification is not satisfied")
                .Candidate("First")
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <string>),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate("Second")
                .AddParameter("Expression", null);
            });
            AddInvalid(dict, False <KeyValuePair <string, bool> >())
            .Result(3,
                    "AllSpecification<Dictionary<String,Boolean>,KeyValuePair<String,Boolean>>([0](FailedMockComplexSpecification[KeyValuePair<String,Boolean>]) And [1](FailedMockComplexSpecification[KeyValuePair<String,Boolean>]))+Failed",
                    c =>
            {
                c.FailedSpecification(
                    typeof(AllSpecification <Dictionary <string, bool>, KeyValuePair <string, bool> >),
                    "One or more elements are not specified")
                .Candidate(dict)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <KeyValuePair <string, bool> >),
                                      "[0] MockComplexSpecification is not satisfied")
                .Candidate(new KeyValuePair <string, bool>("First", true))
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <KeyValuePair <string, bool> >),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate(new KeyValuePair <string, bool>("Second", false))
                .AddParameter("Expression", null);
            });
            AddInvalid(ft, False <int>())
            .Result(6,
                    "AllSpecification<FakeType,Int32>([0](FailedMockComplexSpecification[Int32]) And [1](FailedMockComplexSpecification[Int32]) And [2](FailedMockComplexSpecification[Int32]) And [3](FailedMockComplexSpecification[Int32]) And [4](FailedMockComplexSpecification[Int32]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <FakeType, int>),
                                      "One or more elements are not specified")
                .Candidate(arr)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[0] MockComplexSpecification is not satisfied")
                .Candidate(1)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate(5)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[2] MockComplexSpecification is not satisfied")
                .Candidate(200)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[3] MockComplexSpecification is not satisfied")
                .Candidate(6)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[4] MockComplexSpecification is not satisfied")
                .Candidate(100)
                .AddParameter("Expression", null);
            });
            AddInvalid(arr, FewInt())
            .Result(6,
                    "AllSpecification<Int32[],Int32>([0](MockComplexSpecification[Int32]) And [1](MockComplexSpecification[Int32]) And [2](FailedMockComplexSpecification[Int32]) And [3](MockComplexSpecification[Int32]) And [4](FailedMockComplexSpecification[Int32]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <int[], int>),
                                      "One or more elements are not specified")
                .Candidate(arr)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[2] MockComplexSpecification is not satisfied")
                .Candidate(200)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[4] MockComplexSpecification is not satisfied")
                .Candidate(100)
                .AddParameter("Expression", null);
            });
            AddInvalid(list, FewString())
            .Result(3,
                    "AllSpecification<List<String>,String>([0](MockComplexSpecification[String]) And [1](FailedMockComplexSpecification[String]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <List <string>, string>),
                                      "One or more elements are not specified")
                .Candidate(list)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <string>),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate("Second")
                .AddParameter("Expression", null);
            });
            AddInvalid(dict, FewPair())
            .Result(3,
                    "AllSpecification<Dictionary<String,Boolean>,KeyValuePair<String,Boolean>>([0](MockComplexSpecification[KeyValuePair<String,Boolean>]) And [1](FailedMockComplexSpecification[KeyValuePair<String,Boolean>]))+Failed",
                    c =>
            {
                c.FailedSpecification(
                    typeof(AllSpecification <Dictionary <string, bool>, KeyValuePair <string, bool> >),
                    "One or more elements are not specified")
                .Candidate(dict)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <KeyValuePair <string, bool> >),
                                      "[1] MockComplexSpecification is not satisfied")
                .Candidate(new KeyValuePair <string, bool>("Second", false))
                .AddParameter("Expression", null);
            });
            AddInvalid(ft, FewInt())
            .Result(6,
                    "AllSpecification<FakeType,Int32>([0](MockComplexSpecification[Int32]) And [1](MockComplexSpecification[Int32]) And [2](FailedMockComplexSpecification[Int32]) And [3](MockComplexSpecification[Int32]) And [4](FailedMockComplexSpecification[Int32]))+Failed",
                    c =>
            {
                c.FailedSpecification(typeof(AllSpecification <FakeType, int>),
                                      "One or more elements are not specified")
                .Candidate(ft)
                .AddParameter("SpecificationForAll", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[2] MockComplexSpecification is not satisfied")
                .Candidate(200)
                .AddParameter("Expression", null);
                c.FailedSpecification(typeof(MockComplexSpecification <int>),
                                      "[4] MockComplexSpecification is not satisfied")
                .Candidate(100)
                .AddParameter("Expression", null);
            });
        }
예제 #32
0
        public LengthBetweenData()
        {
            int[] emptyArr = new int[0], arr = { 1, 2, 3 };
            var   list     = new List <int> {
                1, 2, 3
            };
            var dict = new Dictionary <int, bool> {
                { 1, false }, { 2, true }
            };
            var ft = new FakeType {
                Fourth = new[] { 1, 2, 3 }
            };
            var ift = new InterFakeType();

            AddValid("", 0, 0)
            .Result("LengthBetweenSpecification<String>")
            .NegationResult("NotLengthBetweenSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <string>),
                                                 "Object length is between [0] and [0]")
                            .Candidate("")
                            .AddParameter("MinLength", 0)
                            .AddParameter("MaxLength", 0));
            AddValid("test", 1, 4)
            .Result("LengthBetweenSpecification<String>")
            .NegationResult("NotLengthBetweenSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <string>),
                                                 "Object length is between [1] and [4]")
                            .Candidate("test")
                            .AddParameter("MinLength", 1)
                            .AddParameter("MaxLength", 4));
            AddValid(emptyArr, 0, 0)
            .Result("LengthBetweenSpecification<Int32[]>")
            .NegationResult("NotLengthBetweenSpecification<Int32[]>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <int[]>),
                                                 "Object length is between [0] and [0]")
                            .Candidate(emptyArr)
                            .AddParameter("MinLength", 0)
                            .AddParameter("MaxLength", 0));
            AddValid(arr, 2, 3)
            .Result("LengthBetweenSpecification<Int32[]>")
            .NegationResult("NotLengthBetweenSpecification<Int32[]>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <int[]>),
                                                 "Object length is between [2] and [3]")
                            .Candidate(arr)
                            .AddParameter("MinLength", 2)
                            .AddParameter("MaxLength", 3));
            AddValid(list, -1, 10)
            .Result("LengthBetweenSpecification<List<Int32>>")
            .NegationResult("NotLengthBetweenSpecification<List<Int32>>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <List <int> >),
                                                 "Object length is between [-1] and [10]")
                            .Candidate(list)
                            .AddParameter("MinLength", -1)
                            .AddParameter("MaxLength", 10));
            AddValid(dict, 0, 5)
            .Result("LengthBetweenSpecification<Dictionary<Int32,Boolean>>")
            .NegationResult("NotLengthBetweenSpecification<Dictionary<Int32,Boolean>>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <Dictionary <int, bool> >),
                                                 "Object length is between [0] and [5]")
                            .Candidate(dict)
                            .AddParameter("MinLength", 0)
                            .AddParameter("MaxLength", 5));
            AddValid(ft, 0, 3)
            .Result("LengthBetweenSpecification<FakeType>")
            .NegationResult("NotLengthBetweenSpecification<FakeType>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <FakeType>),
                                                 "Object length is between [0] and [3]")
                            .Candidate(ft)
                            .AddParameter("MinLength", 0)
                            .AddParameter("MaxLength", 3));
            AddValid(ift, 1, 1)
            .Result("LengthBetweenSpecification<InterFakeType>")
            .NegationResult("NotLengthBetweenSpecification<InterFakeType>+Failed", c => c
                            .FailedSpecification(typeof(LengthBetweenSpecification <InterFakeType>),
                                                 "Object length is between [1] and [1]")
                            .Candidate(ift)
                            .AddParameter("MinLength", 1)
                            .AddParameter("MaxLength", 1));

            AddInvalid("", 1, 10)
            .NegationResult("NotLengthBetweenSpecification<String>")
            .Result("LengthBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <string>),
                                         "Object length is not between [1] and [10]")
                    .Candidate("")
                    .AddParameter("MinLength", 1)
                    .AddParameter("MaxLength", 10));
            AddInvalid("test", 10, 20)
            .NegationResult("NotLengthBetweenSpecification<String>")
            .Result("LengthBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <string>),
                                         "Object length is not between [10] and [20]")
                    .Candidate("test")
                    .AddParameter("MinLength", 10)
                    .AddParameter("MaxLength", 20));
            AddInvalid(emptyArr, 1, 2)
            .NegationResult("NotLengthBetweenSpecification<Int32[]>")
            .Result("LengthBetweenSpecification<Int32[]>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <int[]>),
                                         "Object length is not between [1] and [2]")
                    .Candidate(emptyArr)
                    .AddParameter("MinLength", 1)
                    .AddParameter("MaxLength", 2));
            AddInvalid(arr, -5, -1)
            .NegationResult("NotLengthBetweenSpecification<Int32[]>")
            .Result("LengthBetweenSpecification<Int32[]>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <int[]>),
                                         "Object length is not between [-5] and [-1]")
                    .Candidate(arr)
                    .AddParameter("MinLength", -5)
                    .AddParameter("MaxLength", -1));
            AddInvalid(list, 0, 1)
            .NegationResult("NotLengthBetweenSpecification<List<Int32>>")
            .Result("LengthBetweenSpecification<List<Int32>>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <List <int> >),
                                         "Object length is not between [0] and [1]")
                    .Candidate(list)
                    .AddParameter("MinLength", 0)
                    .AddParameter("MaxLength", 1));
            AddInvalid(dict, 0, 1)
            .NegationResult("NotLengthBetweenSpecification<Dictionary<Int32,Boolean>>")
            .Result("LengthBetweenSpecification<Dictionary<Int32,Boolean>>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <Dictionary <int, bool> >),
                                         "Object length is not between [0] and [1]")
                    .Candidate(dict)
                    .AddParameter("MinLength", 0)
                    .AddParameter("MaxLength", 1));
            AddInvalid(ft, 4, 6)
            .NegationResult("NotLengthBetweenSpecification<FakeType>")
            .Result("LengthBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <FakeType>),
                                         "Object length is not between [4] and [6]")
                    .Candidate(ft)
                    .AddParameter("MinLength", 4)
                    .AddParameter("MaxLength", 6));
            AddInvalid(ift, 4, 6)
            .NegationResult("NotLengthBetweenSpecification<InterFakeType>")
            .Result("LengthBetweenSpecification<InterFakeType>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <InterFakeType>),
                                         "Object length is not between [4] and [6]")
                    .Candidate(ift)
                    .AddParameter("MinLength", 4)
                    .AddParameter("MaxLength", 6));
            AddInvalid("null", 0, 1)
            .NegationResult("NotLengthBetweenSpecification<String>")
            .Result("LengthBetweenSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <string>),
                                         "Object length is not between [0] and [1]")
                    .Candidate(null)
                    .AddParameter("MinLength", 0)
                    .AddParameter("MaxLength", 1));
            AddInvalid(new FakeType {
                Second = "null"
            }, 0, 0)
            .NegationResult("NotLengthBetweenSpecification<FakeType>")
            .Result("LengthBetweenSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(LengthBetweenSpecification <FakeType>),
                                         "Object length is not between [0] and [0]")
                    .Candidate(null)
                    .AddParameter("MinLength", 0)
                    .AddParameter("MaxLength", 0));
        }
예제 #33
0
 public FakeTarget(FakeType type)
 {
     Type = type;
 }
예제 #34
0
        public LessThanData()
        {
            var comparer           = new FakeTypeComparer();
            var intComparer        = new FakeIntComparer();
            ComparableFakeType cmp = new ComparableFakeType {
                First = 116
            },
                               cmp2 = new ComparableFakeType {
                First = 154
            };
            ComparableInterFakeType cmpInter1 = new ComparableInterFakeType(),
                                    cmpInter2 = new ComparableInterFakeType(),
                                    cmpInter3 = new ComparableInterFakeType {
                Third = true
            };
            FakeType cmpFakeType = new FakeType {
                First = 116
            },
                     cmpFakeType2 = new FakeType {
                First = 154
            };

            AddValid(1, 5, null)
            .Result("LessThanSpecification<Int32>")
            .NegationResult("NotLessThanSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <int>), "Object is lower than [5]")
                            .Candidate(1)
                            .AddParameter("LessThan", 5));
            AddValid(-1, 1, null)
            .Result("LessThanSpecification<Int32>")
            .NegationResult("NotLessThanSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <int>), "Object is lower than [1]")
                            .Candidate(-1)
                            .AddParameter("LessThan", 1));
            AddValid(-9, -1, intComparer)
            .Result("LessThanSpecification<Int32>")
            .NegationResult("NotLessThanSpecification<Int32>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <int>), "Object is lower than [-1]")
                            .Candidate(-9)
                            .AddParameter("LessThan", -1));
            AddValid(5.74, 5.75, null)
            .Result("LessThanSpecification<Double>")
            .NegationResult("NotLessThanSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <double>), "Object is lower than [5.75]")
                            .Candidate(5.74)
                            .AddParameter("LessThan", 5.75));
            AddValid(-2.5, 0.0, null)
            .Result("LessThanSpecification<Double>")
            .NegationResult("NotLessThanSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <double>), "Object is lower than [0]")
                            .Candidate(-2.5)
                            .AddParameter("LessThan", 0.0));
            AddValid(-5.75, -5.74, null)
            .Result("LessThanSpecification<Double>")
            .NegationResult("NotLessThanSpecification<Double>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <double>), "Object is lower than [-5.74]")
                            .Candidate(-5.75)
                            .AddParameter("LessThan", -5.74));
            AddValid(false, true, null)
            .Result("LessThanSpecification<Boolean>")
            .NegationResult("NotLessThanSpecification<Boolean>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <bool>), "Object is lower than [True]")
                            .Candidate(false)
                            .AddParameter("LessThan", true));
            AddValid("123", "124", null)
            .Result("LessThanSpecification<String>")
            .NegationResult("NotLessThanSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <string>), "Object is lower than [124]")
                            .Candidate("123")
                            .AddParameter("LessThan", "124"));
            AddValid("123", "1234", null)
            .Result("LessThanSpecification<String>")
            .NegationResult("NotLessThanSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <string>), "Object is lower than [1234]")
                            .Candidate("123")
                            .AddParameter("LessThan", "1234"));
            AddValid("null", "test", null)
            .Result("LessThanSpecification<String>")
            .NegationResult("NotLessThanSpecification<String>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <string>), "Object is lower than [test]")
                            .Candidate(null)
                            .AddParameter("LessThan", "test"));
            AddValid(DateTime.Parse("2018-01-15"), DateTime.Parse("2019-07-11"), null)
            .Result("LessThanSpecification<DateTime>")
            .NegationResult("NotLessThanSpecification<DateTime>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <DateTime>),
                                                 $"Object is lower than \\[{DateTimeRegexPattern}\\]")
                            .Candidate(DateTime.Parse("2018-01-15"))
                            .AddParameter("LessThan", DateTime.Parse("2019-07-11")));
            AddValid(DateTime.Parse("2019-07-01"), DateTime.Parse("2019-07-11"), null)
            .Result("LessThanSpecification<DateTime>")
            .NegationResult("NotLessThanSpecification<DateTime>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <DateTime>),
                                                 $"Object is lower than \\[{DateTimeRegexPattern}\\]")
                            .Candidate(DateTime.Parse("2019-07-01"))
                            .AddParameter("LessThan", DateTime.Parse("2019-07-11")));
            AddValid(cmp, cmp2, null)
            .Result("LessThanSpecification<ComparableFakeType>")
            .NegationResult("NotLessThanSpecification<ComparableFakeType>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <ComparableFakeType>),
                                                 "Object is lower than [Fake(154)]")
                            .Candidate(cmp)
                            .AddParameter("LessThan", cmp2));
            AddValid(new ComparableFakeType {
                Second = "null"
            }, new ComparableFakeType(), null)
            .Result("LessThanSpecification<ComparableFakeType>")
            .NegationResult("NotLessThanSpecification<ComparableFakeType>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <ComparableFakeType>),
                                                 "Object is lower than [Fake(0)]")
                            .Candidate(null)
                            .AddParameter("LessThan", new ComparableFakeType()));
            AddValid(cmpInter1, cmpInter3, null)
            .Result("LessThanSpecification<ComparableInterFakeType>")
            .NegationResult("NotLessThanSpecification<ComparableInterFakeType>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <ComparableInterFakeType>),
                                                 "Object is lower than [FluentSpecification.Tests.Mocks.ComparableInterFakeType]")
                            .Candidate(cmpInter1)
                            .AddParameter("LessThan", cmpInter3));
            AddValid(cmpFakeType, cmpFakeType2, comparer)
            .Result("LessThanSpecification<FakeType>")
            .NegationResult("NotLessThanSpecification<FakeType>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <FakeType>),
                                                 "Object is lower than [Fake(154)]")
                            .Candidate(cmpFakeType)
                            .AddParameter("LessThan", cmpFakeType2));
            AddValid(new FakeType {
                Second = "null"
            }, new FakeType(), comparer)
            .Result("LessThanSpecification<FakeType>")
            .NegationResult("NotLessThanSpecification<FakeType>+Failed", c => c
                            .FailedSpecification(typeof(LessThanSpecification <FakeType>), "Object is lower than [Fake(0)]")
                            .Candidate(null)
                            .AddParameter("LessThan", new FakeType()));

            ComparableFakeType notCmp1 = new ComparableFakeType {
                First = 11
            },
                               notCmp2 = new ComparableFakeType {
                First = 10
            },
                               notCmp3 = new ComparableFakeType {
                First = 10
            };
            FakeType notCmpFakeType1 = new FakeType {
                First = 11
            },
                     notCmpFakeType2 = new FakeType {
                First = 10
            },
                     notCmpFakeType3 = new FakeType {
                First = 10
            };

            AddInvalid(2, 2, null)
            .NegationResult("NotLessThanSpecification<Int32>")
            .Result("LessThanSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <int>), "Object is greater than or equal to [2]")
                    .Candidate(2)
                    .AddParameter("LessThan", 2));
            AddInvalid(-2, -2, null)
            .NegationResult("NotLessThanSpecification<Int32>")
            .Result("LessThanSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <int>), "Object is greater than or equal to [-2]")
                    .Candidate(-2)
                    .AddParameter("LessThan", -2));
            AddInvalid(1, -1, null)
            .NegationResult("NotLessThanSpecification<Int32>")
            .Result("LessThanSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <int>), "Object is greater than or equal to [-1]")
                    .Candidate(1)
                    .AddParameter("LessThan", -1));
            AddInvalid(5, 3, null)
            .NegationResult("NotLessThanSpecification<Int32>")
            .Result("LessThanSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <int>), "Object is greater than or equal to [3]")
                    .Candidate(5)
                    .AddParameter("LessThan", 3));
            AddInvalid(-1, -10, intComparer)
            .NegationResult("NotLessThanSpecification<Int32>")
            .Result("LessThanSpecification<Int32>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <int>), "Object is greater than or equal to [-10]")
                    .Candidate(-1)
                    .AddParameter("LessThan", -10));
            AddInvalid(3.5, 3.5, null)
            .NegationResult("NotLessThanSpecification<Double>")
            .Result("LessThanSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <double>),
                                         "Object is greater than or equal to [3.5]")
                    .Candidate(3.5)
                    .AddParameter("LessThan", 3.5));
            AddInvalid(-3.5, -3.5, null)
            .NegationResult("NotLessThanSpecification<Double>")
            .Result("LessThanSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <double>),
                                         "Object is greater than or equal to [-3.5]")
                    .Candidate(-3.5)
                    .AddParameter("LessThan", -3.5));
            AddInvalid(5.74, 3.74, null)
            .NegationResult("NotLessThanSpecification<Double>")
            .Result("LessThanSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <double>),
                                         "Object is greater than or equal to [3.74]")
                    .Candidate(5.74)
                    .AddParameter("LessThan", 3.74));
            AddInvalid(-3.74, -5.74, null)
            .NegationResult("NotLessThanSpecification<Double>")
            .Result("LessThanSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <double>),
                                         "Object is greater than or equal to [-5.74]")
                    .Candidate(-3.74)
                    .AddParameter("LessThan", -5.74));
            AddInvalid(5.74, -3.74, null)
            .NegationResult("NotLessThanSpecification<Double>")
            .Result("LessThanSpecification<Double>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <double>),
                                         "Object is greater than or equal to [-3.74]")
                    .Candidate(5.74)
                    .AddParameter("LessThan", -3.74));
            AddInvalid(true, false, null)
            .NegationResult("NotLessThanSpecification<Boolean>")
            .Result("LessThanSpecification<Boolean>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <bool>),
                                         "Object is greater than or equal to [False]")
                    .Candidate(true)
                    .AddParameter("LessThan", false));
            AddInvalid(false, false, null)
            .NegationResult("NotLessThanSpecification<Boolean>")
            .Result("LessThanSpecification<Boolean>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <bool>),
                                         "Object is greater than or equal to [False]")
                    .Candidate(false)
                    .AddParameter("LessThan", false));
            AddInvalid("123", "122", null)
            .NegationResult("NotLessThanSpecification<String>")
            .Result("LessThanSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <string>),
                                         "Object is greater than or equal to [122]")
                    .Candidate("123")
                    .AddParameter("LessThan", "122"));
            AddInvalid("1234", "123", null)
            .NegationResult("NotLessThanSpecification<String>")
            .Result("LessThanSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <string>),
                                         "Object is greater than or equal to [123]")
                    .Candidate("1234")
                    .AddParameter("LessThan", "123"));
            AddInvalid("123", "123", null)
            .NegationResult("NotLessThanSpecification<String>")
            .Result("LessThanSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <string>),
                                         "Object is greater than or equal to [123]")
                    .Candidate("123")
                    .AddParameter("LessThan", "123"));
            AddInvalid("test1", null, null)
            .NegationResult("NotLessThanSpecification<String>")
            .Result("LessThanSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <string>),
                                         "Object is greater than or equal to [null]")
                    .Candidate("test1")
                    .AddParameter("LessThan", null));
            AddInvalid("null", null, null)
            .NegationResult("NotLessThanSpecification<String>")
            .Result("LessThanSpecification<String>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <string>),
                                         "Object is greater than or equal to [null]")
                    .Candidate(null)
                    .AddParameter("LessThan", null));
            AddInvalid(DateTime.Parse("2019-11-15"), DateTime.Parse("2019-07-11"), null)
            .NegationResult("NotLessThanSpecification<DateTime>")
            .Result("LessThanSpecification<DateTime>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <DateTime>),
                                         $"Object is greater than or equal to \\[{DateTimeRegexPattern}\\]")
                    .Candidate(DateTime.Parse("2019-11-15"))
                    .AddParameter("LessThan", DateTime.Parse("2019-07-11")));
            AddInvalid(DateTime.Parse("2019-07-11"), DateTime.Parse("2019-07-11"), null)
            .NegationResult("NotLessThanSpecification<DateTime>")
            .Result("LessThanSpecification<DateTime>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <DateTime>),
                                         $"Object is greater than or equal to \\[{DateTimeRegexPattern}\\]")
                    .Candidate(DateTime.Parse("2019-07-11"))
                    .AddParameter("LessThan", DateTime.Parse("2019-07-11")));
            AddInvalid(notCmp1, notCmp2, null)
            .NegationResult("NotLessThanSpecification<ComparableFakeType>")
            .Result("LessThanSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <ComparableFakeType>),
                                         "Object is greater than or equal to [Fake(10)]")
                    .Candidate(notCmp1)
                    .AddParameter("LessThan", notCmp2));
            AddInvalid(notCmp2, notCmp3, null)
            .NegationResult("NotLessThanSpecification<ComparableFakeType>")
            .Result("LessThanSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <ComparableFakeType>),
                                         "Object is greater than or equal to [Fake(10)]")
                    .Candidate(notCmp2)
                    .AddParameter("LessThan", notCmp3));
            AddInvalid(new ComparableFakeType {
                Second = "null"
            }, null, null)
            .NegationResult("NotLessThanSpecification<ComparableFakeType>")
            .Result("LessThanSpecification<ComparableFakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <ComparableFakeType>),
                                         "Object is greater than or equal to [null]")
                    .Candidate(null)
                    .AddParameter("LessThan", null));
            AddInvalid(cmpInter1, cmpInter2, null)
            .NegationResult("NotLessThanSpecification<ComparableInterFakeType>")
            .Result("LessThanSpecification<ComparableInterFakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <ComparableInterFakeType>),
                                         "Object is greater than or equal to [FluentSpecification.Tests.Mocks.ComparableInterFakeType]")
                    .Candidate(cmpInter1)
                    .AddParameter("LessThan", cmpInter2));
            AddInvalid(notCmpFakeType1, notCmpFakeType2, comparer)
            .NegationResult("NotLessThanSpecification<FakeType>")
            .Result("LessThanSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <FakeType>),
                                         "Object is greater than or equal to [Fake(10)]")
                    .Candidate(notCmpFakeType1)
                    .AddParameter("LessThan", notCmpFakeType2));
            AddInvalid(notCmpFakeType2, notCmpFakeType3, comparer)
            .NegationResult("NotLessThanSpecification<FakeType>")
            .Result("LessThanSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <FakeType>),
                                         "Object is greater than or equal to [Fake(10)]")
                    .Candidate(notCmpFakeType2)
                    .AddParameter("LessThan", notCmpFakeType3));
            AddInvalid(new FakeType {
                Second = "null"
            }, null, comparer)
            .NegationResult("NotLessThanSpecification<FakeType>")
            .Result("LessThanSpecification<FakeType>+Failed", c => c
                    .FailedSpecification(typeof(LessThanSpecification <FakeType>),
                                         "Object is greater than or equal to [null]")
                    .Candidate(null)
                    .AddParameter("LessThan", null));
        }
예제 #35
0
파일: Ballot.cs 프로젝트: dbrgn/pi-vote
        /// <summary>
        /// Creates a new ballot for a voter.
        /// </summary>
        /// <param name="vota">Vota the voter wishes to cast for each option.</param>
        /// <param name="parameters">Cryptographic parameters.</param>
        /// <param name="publicKey">Public key of voting authorities.</param>
        /// <param name="progress">Report progress up.</param>
        /// <param name="fakeType">What fake to create?</param>
        public Ballot(IEnumerable<int> vota, BaseParameters parameters, Question questionParameters, BigInt publicKey, FakeType fakeType)
        {
            if (vota == null)
            throw new ArgumentNullException("vota");
              if (parameters == null)
            throw new ArgumentNullException("parameters");
              if (publicKey == null)
            throw new ArgumentNullException("publicKey");
              if (vota.Count() != questionParameters.Options.Count())
            throw new ArgumentException("Bad vota.");
              if (!vota.All(votum => votum.InRange(0, 1)))
            throw new ArgumentException("Bad vota.");
              if (vota.Sum() != questionParameters.MaxVota)
            throw new ArgumentException("Bad vota.");

              Votes = new List<Vote>();
              BigInt nonceSum = new BigInt(0);
              Vote voteSum = null;

              List<Tuple<int, BigInt, BaseParameters, BigInt>> voteWorkList = new List<Tuple<int, BigInt, BaseParameters, BigInt>>();

              foreach (int votum in vota)
              {
            BigInt nonce = parameters.Random();
            nonceSum += nonce;
            voteWorkList.Add(new Tuple<int, BigInt, BaseParameters, BigInt>(votum, nonce, parameters, publicKey));
              }

              List<Vote> voteList = Parallel
            .Work<Tuple<int, BigInt, BaseParameters, BigInt>, Vote>(CreateVote, voteWorkList, null);

              foreach (Vote vote in voteList)
              {
            voteSum = voteSum == null ? vote : voteSum + vote;
            Votes.Add(vote);
              }

              SumProves = new List<Proof>();
              for (int proofIndex = 0; proofIndex < parameters.ProofCount; proofIndex++)
              {
            SumProves.Add(new Proof(nonceSum * 12, voteSum, publicKey, parameters, fakeType));
              }
        }
예제 #36
0
 public FakeCommonTypeBuilder AddProperty(string name, FakeType propertyType, PropertyMethods propertyMethods, params FakeAttribute[] propertyFakeAttributes)
 {
     properties.Add(new FakeProperty(name, propertyType, propertyMethods, propertyFakeAttributes));
     return(this);
 }
예제 #37
0
 private static Type CreateReflectionType(FakeType fakeType)
 {
     return(fakeType.Type ?? CreateReflectionType(fakeType.FullName, fakeType.BaseType));
 }