public void UpdateRelationshipAuthorizations_WithValidUserDTO_AuthorizationsObjectIsValid_ValidQuery()
        {
            // Arrange
            var queryGenerator = CreateFrienshipQueryGenerator();
            var userDTO        = A.Fake <IUserDTO>();

            _fakeUserQueryValidator.ArrangeCanUserBeIdentified(userDTO, true);
            _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter();

            // Act
            var result1 = queryGenerator.GetUpdateRelationshipAuthorizationsWithQuery(userDTO, GenerateFriendshipAuthorizations(true, true));
            var result2 = queryGenerator.GetUpdateRelationshipAuthorizationsWithQuery(userDTO, GenerateFriendshipAuthorizations(true, false));
            var result3 = queryGenerator.GetUpdateRelationshipAuthorizationsWithQuery(userDTO, GenerateFriendshipAuthorizations(false, true));
            var result4 = queryGenerator.GetUpdateRelationshipAuthorizationsWithQuery(userDTO, GenerateFriendshipAuthorizations(false, false));

            // Assert
            string idParameter = UserQueryGeneratorHelper.GenerateParameterExpectedResult(userDTO);

            Assert.AreEqual(result1, GenerateUpdateQuery(true, true, idParameter));
            Assert.AreEqual(result2, GenerateUpdateQuery(true, false, idParameter));
            Assert.AreEqual(result3, GenerateUpdateQuery(false, true, idParameter));
            Assert.AreEqual(result4, GenerateUpdateQuery(false, false, idParameter));

            _fakeUserQueryValidator.CallsTo(x => x.ThrowIfUserCannotBeIdentified(userDTO)).MustHaveHappened(Repeated.Exactly.Times(4));
        }
Ejemplo n.º 2
0
        public void PublishMessage_ExpectedQuery()
        {
            var text          = TestHelper.GenerateString();
            var formattedText = TestHelper.GenerateString();
            var user          = A.Fake <IUserIdentifier>();

            var parameter = A.Fake <IPublishMessageParameters>();

            parameter.CallsTo(x => x.Text).Returns(text);
            parameter.CallsTo(x => x.Recipient).Returns(user);

            _fakeTwitterStringFormatter.CallsTo(x => x.TwitterEncode(text)).Returns(formattedText);

            // Arrange
            var queryGenerator = CreateMessageQueryGenerator();
            var expectedIdentifierParameter = Guid.NewGuid().ToString();
            var expectedResult = string.Format(Resources.Message_NewMessage, formattedText, expectedIdentifierParameter);

            _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter(expectedIdentifierParameter);

            // Act
            var result = queryGenerator.GetPublishMessageQuery(parameter);

            // Assert
            Assert.AreEqual(result, expectedResult);

            _fakeMessageQueryValidator.CallsTo(x => x.ThrowIfMessageCannotBePublished(parameter)).MustHaveHappened();
        }
Ejemplo n.º 3
0
        private IUserDTO GenerateUserDTO(bool isValid)
        {
            var userDTO = A.Fake <IUserDTO>();

            _fakeUserQueryValidator.CallsTo(x => x.CanUserBeIdentified(userDTO)).Returns(isValid);
            _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter();
            return(userDTO);
        }
        public void VerifyGetPublishMessageQuery_WithTextAndMessageDTO(
            bool canMessageBePublished,
            bool isRecipientValid,
            bool isRecipientIdValid,
            bool isRecipientScreenNameValid,
            bool expectedValue)
        {
            var text        = TestHelper.GenerateString();
            var twitterText = TestHelper.GenerateString();

            _fakeTwitterStringFormatter.CallsTo(x => x.TwitterEncode(It.IsAny <string>())).Returns(twitterText);

            var messageDTO = A.Fake <IMessageDTO>();

            messageDTO.CallsTo(x => x.Text).Returns(text);

            _fakeMessageQueryValidator.CallsTo(x => x.IsMessageTextValid(text)).Returns(canMessageBePublished);
            _fakeMessageQueryValidator.CallsTo(x => x.CanMessageDTOBePublished(messageDTO)).Returns(canMessageBePublished);

            ArrangeMessageDTORecipient(messageDTO, isRecipientValid, isRecipientIdValid, isRecipientScreenNameValid);

            // Arrange
            var queryGenerator = CreateMessageQueryGenerator();
            var expectedIdentifierParameter = Guid.NewGuid().ToString();
            var expectedResult = String.Format(Resources.Message_NewMessage, twitterText, expectedIdentifierParameter);

            if (isRecipientValid)
            {
                _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter(expectedIdentifierParameter);
            }
            else if (isRecipientIdValid)
            {
                _fakeUserQueryParameterGenerator.ArrangeGenerateIdParameter(expectedIdentifierParameter);
            }
            else
            {
                _fakeUserQueryParameterGenerator.ArrangeGenerateScreenNameParameter(expectedIdentifierParameter);
            }

            // Act
            var result = queryGenerator.GetPublishMessageQuery(messageDTO);

            // Assert
            Assert.AreEqual(result, expectedValue ? expectedResult : null);
        }
        public void TestInitialize()
        {
            _fakeBuilder = new FakeClassBuilder <FriendshipQueryGenerator>();
            _fakeUserQueryParameterGenerator = _fakeBuilder.GetFake <IUserQueryParameterGenerator>();
            _fakeUserQueryValidator          = _fakeBuilder.GetFake <IUserQueryValidator>();

            _fakeUserQueryParameterGenerator.ArrangeGenerateIdParameter();
            _fakeUserQueryParameterGenerator.ArrangeGenerateScreenNameParameter();
            _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter();
            _fakeUserQueryValidator.ArrangeIsUserIdValid();
        }
Ejemplo n.º 6
0
        private IUserDTO GenerateUserDTO(bool isValid)
        {
            var userDTO = A.Fake <IUserDTO>();

            _fakeUserQueryValidator.CallsTo(x => x.CanUserBeIdentified(userDTO)).Returns(isValid);

            if (!isValid)
            {
                _fakeUserQueryValidator.CallsTo(x => x.ThrowIfUserCannotBeIdentified(userDTO)).Throws(new ArgumentException());
                _fakeUserQueryValidator.CallsTo(x => x.ThrowIfUserCannotBeIdentified(userDTO, It.IsAny <string>())).Throws(new ArgumentException());
            }

            _fakeUserQueryParameterGenerator.ArrangeGenerateIdOrScreenNameParameter();
            return(userDTO);
        }