public void Execute_Throws_Exception_When_Company_Not_Found() { // Setup InitializeTestEntities(); int id = _company.Id + 1; Mock <CompanyByIdQuery> query = QueryTestUtils.GenerateCompanyByIdQueryMock(); query.Setup(x => x.Execute()).Returns((Company)null); _serviceFactory.Setup(x => x.GetService <CompanyByIdQuery>()).Returns(query.Object); // Act try { new CreateContactCommand(_serviceFactory.Object).WithCompanyId(id) .SetName("Name") .SetDirectPhone("111-111-1111") .SetMobilePhone("222-222-2222") .SetExtension("33") .SetEmail("*****@*****.**") .SetAssistant("Assistant") .SetReferredBy("Referred By") .SetNotes("Notes") .RequestedByUserId(_user.Id) .Execute(); Assert.Fail("Command did not throw an exception"); } // Verify catch (MJLEntityNotFoundException ex) { Assert.AreEqual(typeof(Company), ex.EntityType, "MJLEntityNotFoundException's entity type was incorrect"); Assert.AreEqual(id.ToString(), ex.IdValue, "MJLEntityNotFoundException's id value was incorrect"); } }
public void Execute_Throws_Exception_When_Company_Not_Found() { // Setup InitializeTestEntities(); int id = _company.Id + 1; Mock <CompanyByIdQuery> query = QueryTestUtils.GenerateCompanyByIdQueryMock(); query.Setup(x => x.Execute()).Returns((Company)null); _serviceFactory.Setup(x => x.GetService <CompanyByIdQuery>()).Returns(query.Object); // Act try { new EditCompanyCommand(_serviceFactory.Object).WithCompanyId(id) .SetName("Name") .SetPhone("555-555-5555") .SetCity("City") .SetState("State") .SetZip("01234") .SetMetroArea("Metro") .SetIndustry("Industry") .SetNotes("Notes") .RequestedByUserId(_user.Id) .Execute(); Assert.Fail("Command did not throw an exception"); } // Verify catch (MJLEntityNotFoundException ex) { Assert.AreEqual(typeof(Company), ex.EntityType, "MJLEntityNotFoundException's entity type was incorrect"); Assert.AreEqual(id.ToString(), ex.IdValue, "MJLEntityNotFoundException's id value was incorrect"); } }
public void RelationalOperatorTypePromotion() { IEdmModel model = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory); BinaryOperatorKind[] relationalOperatorKinds = new BinaryOperatorKind[] { BinaryOperatorKind.Equal, BinaryOperatorKind.NotEqual, BinaryOperatorKind.GreaterThan, BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan, BinaryOperatorKind.LessThanOrEqual }; var testCases = ComputeRelationalTestCases().Concat(ComputeRelationalErrorTestCases()); this.CombinatorialEngineProvider.RunCombinations( testCases, relationalOperatorKinds, (testCase, relationalOperatorKind) => { string filter = testCase.Arguments[0] + " " + QueryTestUtils.ToOperatorName(relationalOperatorKind) + " " + testCase.Arguments[1]; string errorMessage = null; if (testCase.ExpectedErrorMessage != null) { errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, relationalOperatorKind); } var actualFilter = this.BindFilter(model, filter, errorMessage); if (errorMessage == null) { this.Assert.IsNotNull(actualFilter, "Filter must not be null."); BinaryOperatorNode binaryOperatorNode = null; if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert) { binaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as BinaryOperatorNode; } else { binaryOperatorNode = actualFilter.Expression as BinaryOperatorNode; } this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator at the top of the filter."); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, binaryOperatorNode.Left.TypeReference, this.Assert); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, binaryOperatorNode.Right.TypeReference, this.Assert); } }); }
private void InitializeTestEntities() { _jobSearch = new JobSearch(); _company = new Company { Tasks = new List <Task>(), JobSearch = _jobSearch }; _user = new User(); _contact = new Contact { Company = _company }; _unitOfWork.Users.Add(_user); _unitOfWork.Companies.Add(_company); _unitOfWork.Contacts.Add(_contact); _unitOfWork.Commit(); _testDate = new DateTime(2011, 1, 2, 3, 4, 5); // Mocks _companyAuthMock = new Mock <IProcess <CompanyQueryAuthorizationParams, AuthorizationResultViewModel> >(); _companyAuthMock.Setup(x => x.Execute(It.IsAny <CompanyQueryAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true }); _contactAuthMock = new Mock <IProcess <ContactAutorizationParams, AuthorizationResultViewModel> >(); _contactAuthMock.Setup(x => x.Execute(It.IsAny <ContactAutorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true }); _serviceFactory = new Mock <IServiceFactory>(); _serviceFactory.Setup(x => x.GetService <IUnitOfWork>()).Returns(_unitOfWork); _searchProvider = new Mock <ISearchProvider>(); _serviceFactory.Setup(x => x.GetService <ISearchProvider>()).Returns(_searchProvider.Object); _userQuery = new Mock <UserByIdQuery>(_unitOfWork); _userQuery.Setup(x => x.Execute()).Returns(_user); _serviceFactory.Setup(x => x.GetService <UserByIdQuery>()).Returns(_userQuery.Object); _companyQuery = QueryTestUtils.GenerateCompanyByIdQueryMock(); _companyQuery.Setup(x => x.Execute()).Returns(_company); _serviceFactory.Setup(x => x.GetService <CompanyByIdQuery>()).Returns(_companyQuery.Object); _contactQuery = new Mock <ContactByIdQuery>(_unitOfWork, _contactAuthMock.Object); _contactQuery.Setup(x => x.Execute()).Returns(_contact); _serviceFactory.Setup(x => x.GetService <ContactByIdQuery>()).Returns(_contactQuery.Object); _updateMetricsCmd = new Mock <UpdateJobSearchMetricsCommand>(_serviceFactory.Object); _serviceFactory.Setup(x => x.GetService <UpdateJobSearchMetricsCommand>()).Returns(_updateMetricsCmd.Object); _validator = new Mock <IValidator <Task> >(); _validator.Setup(x => x.Validate(It.IsAny <Task>())).Returns(new ValidationResult()); _serviceFactory.Setup(x => x.GetService <IValidator <Task> >()).Returns(_validator.Object); }
public void NegateTypePromotion() { var metadata = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory); this.CombinatorialEngineProvider.RunCombinations( ComputeUnaryTestCases(UnaryOperatorKind.Negate).Concat(ComputeUnaryErrorTestCases(UnaryOperatorKind.Negate)), (testCase) => { string filter = "-" + testCase.Arguments[0] + " le 0"; string errorMessage = null; if (testCase.ExpectedErrorMessage != null) { errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, "Negate"); } var actualFilter = this.BindFilter(metadata, filter, errorMessage); if (errorMessage == null) { this.Assert.IsNotNull(actualFilter, "Filter must not be null."); BinaryOperatorNode binaryOperatorNode = null; if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert) { binaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as BinaryOperatorNode; } else { binaryOperatorNode = actualFilter.Expression as BinaryOperatorNode; } this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator at the top of the filter."); UnaryOperatorNode unaryOperatorNode = null; if (binaryOperatorNode.Left.InternalKind == InternalQueryNodeKind.Convert) { unaryOperatorNode = ((ConvertNode)binaryOperatorNode.Left).Source as UnaryOperatorNode; } else { unaryOperatorNode = binaryOperatorNode.Left as UnaryOperatorNode; } this.Assert.IsNotNull(unaryOperatorNode, "Expected a unary operator as the left argument of the binary operator."); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, unaryOperatorNode.Operand.TypeReference, this.Assert); } }); }
private void InitializeTestEntities() { _user = new User(); _company = new Company { Name = "Starting Name", Phone = "333-444-5555", City = "Starting City", State = "Starting State", Zip = "00000", MetroArea = "Starting Metro", Industry = "Starting Industry", Notes = "Starting Notes", Website = "website", JigsawId = 1234, History = new List <CompanyHistory>() }; _unitOfWork.Users.Add(_user); _unitOfWork.Companies.Add(_company); _unitOfWork.Commit(); // Setup mocks _companyAuthMock = new Mock <IProcess <CompanyQueryAuthorizationParams, AuthorizationResultViewModel> >(); _companyAuthMock.Setup(x => x.Execute(It.IsAny <CompanyQueryAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true }); _serviceFactory = new Mock <IServiceFactory>(); _serviceFactory.Setup(x => x.GetService <IUnitOfWork>()).Returns(_unitOfWork); _searchProvider = new Mock <ISearchProvider>(); _serviceFactory.Setup(x => x.GetService <ISearchProvider>()).Returns(_searchProvider.Object); Mock <UserByIdQuery> userQuery = new Mock <UserByIdQuery>(_unitOfWork); userQuery.Setup(x => x.Execute()).Returns(_user); _serviceFactory.Setup(x => x.GetService <UserByIdQuery>()).Returns(userQuery.Object); Mock <CompanyByIdQuery> companyQuery = QueryTestUtils.GenerateCompanyByIdQueryMock(); companyQuery.Setup(x => x.Execute()).Returns(_company); _serviceFactory.Setup(x => x.GetService <CompanyByIdQuery>()).Returns(companyQuery.Object); _validator = new Mock <IValidator <Company> >(); _validator.Setup(x => x.Validate(It.IsAny <Company>())).Returns(new ValidationResult()); _serviceFactory.Setup(x => x.GetService <IValidator <Company> >()).Returns(_validator.Object); }
public void NotTypePromotion() { var metadata = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory); // run over all operator kinds (not, negate) // use all combinations with the same argument types (plain and nullable) this.CombinatorialEngineProvider.RunCombinations( ComputeUnaryTestCases(UnaryOperatorKind.Not).Concat(ComputeUnaryErrorTestCases(UnaryOperatorKind.Not)), (testCase) => { string filter = "not " + testCase.Arguments[0]; string errorMessage = null; if (testCase.ExpectedErrorMessage != null) { errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, "Not"); } var actualFilter = this.BindFilter(metadata, filter, errorMessage); if (errorMessage == null) { this.Assert.IsNotNull(actualFilter, "Filter must not be null."); UnaryOperatorNode unaryOperatorNode = null; if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert) { unaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as UnaryOperatorNode; } else { unaryOperatorNode = actualFilter.Expression as UnaryOperatorNode; } this.Assert.IsNotNull(unaryOperatorNode, "Expected a unary operator at the top of the filter."); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, unaryOperatorNode.Operand.TypeReference, this.Assert); } }); }
public void Init() { _createPositionMock = new Mock <IProcess <CreatePositionParams, PositionDisplayViewModel> >(); _createPositionMock.Setup(x => x.Execute(It.IsAny <CreatePositionParams>())).Returns(new PositionDisplayViewModel()); _verifyTokenMock = new Mock <IProcess <VerifyUserLinkedInAccessTokenParams, UserAccessTokenResultViewModel> >(); _verifyTokenMock.Setup(x => x.Execute(It.IsAny <VerifyUserLinkedInAccessTokenParams>())).Returns(new UserAccessTokenResultViewModel { AccessTokenValid = true }); _createCompanyCmdMock = CommandTestUtils.GenerateCreateCompanyCommandMock(); _createCompanyCmdMock.Setup(x => x.Execute()).Returns(new Company { Id = NEW_COMPANY_ID }); _companyQueryMock = QueryTestUtils.GenerateCompanyByIdQueryMock(); _process = new LinkedInPositionSearchProcesses(_context, _verifyTokenMock.Object, _createCompanyCmdMock.Object, _createPositionMock.Object, _companyQueryMock.Object); // Initialize user with test (but valid) access token data _user = new User { LastVisitedJobSearch = new JobSearch() }; var oauth = new OAuthData { Token = "bfcf3fe4-b4d4-4f37-9d32-292ae9d45347", Secret = "f66673b2-5877-4fbf-80e0-3826ca9f7eed", TokenProvider = TokenProvider.LinkedIn, TokenType = TokenType.AccessToken, }; oauth.LinkedInUsers.Add(_user); _user.LinkedInOAuthData = oauth; _context.Users.Add(_user); _context.OAuthData.Add(oauth); _context.SaveChanges(); }
private static void VerifySingleValueFunctionCallQueryNodesAreEqual(SingleValueFunctionCallNode expected, SingleValueFunctionCallNode actual, AssertionHandler assert) { assert.AreEqual(expected.Name, actual.Name, "The names of the functions are different."); VerifyQueryNodesAreEqual(expected.Parameters, actual.Parameters, assert); QueryTestUtils.VerifyTypesAreEqual(expected.TypeReference, actual.TypeReference, assert); }
private static void VerifySingleComplexNodeAreEqual(SingleComplexNode expected, SingleComplexNode actual, AssertionHandler assert) { VerifyQueryNodesAreEqual(expected.Source, actual.Source, assert); QueryTestUtils.VerifyPropertiesAreEqual(expected.Property, actual.Property, assert); }
private static void VerifyResourceRangeVariableReferenceNodesAreEqual(ResourceRangeVariableReferenceNode expected, ResourceRangeVariableReferenceNode actual, AssertionHandler assert) { QueryTestUtils.VerifyTypesAreEqual(expected.TypeReference, actual.TypeReference, assert); }
private static void VerifyConstantQueryNodesAreEqual(ConstantNode expected, ConstantNode actual, AssertionHandler assert) { assert.AreEqual(expected.Value, actual.Value, "The Value is different."); QueryTestUtils.VerifyTypesAreEqual(expected.TypeReference, actual.TypeReference, assert); }
public void ArithmeticOperatorTypePromotion() { var metadata = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory); BinaryOperatorKind[] arithmeticOperatorKinds = new BinaryOperatorKind[] { BinaryOperatorKind.Add, BinaryOperatorKind.Subtract, BinaryOperatorKind.Multiply, BinaryOperatorKind.Divide, BinaryOperatorKind.Modulo, }; var testCases = ComputeArithmeticTestCases().Concat(ComputeArithmeticErrorTestCases()); this.CombinatorialEngineProvider.RunCombinations( testCases, arithmeticOperatorKinds, (testCase, arithmeticOperatorKind) => { string filter = testCase.Arguments[0] + " " + QueryTestUtils.ToOperatorName(arithmeticOperatorKind) + " " + testCase.Arguments[1] + " le 0"; string errorMessage = null; if (testCase.ExpectedErrorMessage != null) { errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, arithmeticOperatorKind); } var actualFilter = this.BindFilter(metadata, filter, errorMessage); if (errorMessage == null) { this.Assert.IsNotNull(actualFilter, "Filter must not be null."); BinaryOperatorNode binaryOperatorNode = null; if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert) { binaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as BinaryOperatorNode; } else { binaryOperatorNode = actualFilter.Expression as BinaryOperatorNode; } this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator at the top of the filter."); if (binaryOperatorNode.Left.InternalKind == InternalQueryNodeKind.Convert) { binaryOperatorNode = ((ConvertNode)binaryOperatorNode.Left).Source as BinaryOperatorNode; } else { binaryOperatorNode = binaryOperatorNode.Left as BinaryOperatorNode; } this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator as the left argument of the top-level binary operator."); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, binaryOperatorNode.Left.TypeReference, this.Assert); QueryTestUtils.VerifyTypesAreEqual( testCase.ExpectedResultType, binaryOperatorNode.Right.TypeReference, this.Assert); } }); }