Ejemplo n.º 1
0
        public void Handler_ReturnsValue_FromSecretCreator()
        {
            var minLength = FakeData.Int(1, 50);
            var maxLength = FakeData.Int(minLength, 100);
            var secret    = FakeData.String();

            while (secret.Length < minLength)
            {
                secret += FakeData.String();
            }
            while (secret.Length > maxLength)
            {
                secret = secret.Substring(0, secret.Length - 2);
            }
            var secretCreator = new Mock <ICreateSecrets>(MockBehavior.Strict);

            secretCreator.Setup(x => x.CreateSecret(minLength, maxLength))
            .Returns(secret);
            var handler = new HandleRandomSecretQuery(secretCreator.Object);
            var query   = new RandomSecret(minLength, maxLength);

            string result = handler.Handle(query);

            result.ShouldEqual(secret);
            secretCreator.Verify(x => x.CreateSecret(minLength, maxLength), Times.Once);
        }
Ejemplo n.º 2
0
        public void Query_Ctor_Exact_SetsBothMinAndMaxLengthProperties_WhenArgumentIsInRange()
        {
            var exactLength = FakeData.Id();
            var query       = new RandomSecret(exactLength);

            query.MinLength.ShouldEqual(exactLength);
            query.MaxLength.ShouldEqual(exactLength);
        }
Ejemplo n.º 3
0
        public void Query_Ctor_Exact_SetsBothMinAndMaxLengthProperties_WhenArgumentIsInRange()
        {
            var exactLength = new Random().Next(1, int.MaxValue);
            var query       = new RandomSecret(exactLength);

            query.MinLength.ShouldEqual(exactLength);
            query.MaxLength.ShouldEqual(exactLength);
        }
Ejemplo n.º 4
0
        public void Query_Ctor_MinMax_SetsMinAndMaxLengthProperties_WhenArgumentsAreInRange()
        {
            var minLength = FakeData.Int(1, int.MaxValue / 2);
            var maxLength = FakeData.Int(minLength, int.MaxValue);
            var query     = new RandomSecret(minLength, maxLength);

            query.MinLength.ShouldEqual(minLength);
            query.MaxLength.ShouldEqual(maxLength);
        }