示例#1
0
        public async Task Then_Is_Valid_If_All_Params_Are_Supplied()
        {
            //Arrange
            var request = new GetAccountLegalEntitiesForProviderQuery
            {
                ProviderId = 10
            };

            //Act
            var actual = await _validator.ValidateAsync(request);

            //Assert
            Assert.IsTrue(actual.IsValid());
        }
示例#2
0
        public async Task Then_Not_Valid_Is_Returned_If_The_Provider_Id_Is_Not_Supplied()
        {
            //Arrange
            var request = new GetAccountLegalEntitiesForProviderQuery
            {
                ProviderId = 0
            };

            //Act
            var actual = await _validator.ValidateAsync(request);

            //Assert
            Assert.IsFalse(actual.IsValid());
            Assert.IsTrue(actual.ValidationDictionary.ContainsKey(nameof(request.ProviderId)));
        }
        public void Then_An_Argument_Excpetion_Is_Thrown_If_The_Query_Is_Not_Valid(
            GetAccountLegalEntitiesForProviderQuery query,
            [Frozen] Mock <IProviderPermissionService> service,
            [Frozen] Mock <IValidator <GetAccountLegalEntitiesForProviderQuery> > validator,
            GetAccountLegalEntitiesForProviderQueryHandler handler)
        {
            //Arrange
            validator.Setup(x => x.ValidateAsync(It.IsAny <GetAccountLegalEntitiesForProviderQuery>()))
            .ReturnsAsync(new ValidationResult
            {
                ValidationDictionary = new Dictionary <string, string> {
                    { "", "" }
                }
            });

            //Act Assert
            Assert.ThrowsAsync <ArgumentException>(async() => await handler.Handle(query, CancellationToken.None));
        }
 private static void SetupProviderPermissionService(GetAccountLegalEntitiesForProviderQuery query, Mock <IProviderPermissionService> service)
 {
     service.Setup(x => x.GetPermissionsByProviderId(query.ProviderId)).ReturnsAsync(
         new List <ProviderPermission>
     {
         new ProviderPermission(new Domain.Entities.ProviderPermission
         {
             AccountId          = 1,
             AccountLegalEntity = new AccountLegalEntity
             {
                 AccountLegalEntityName = "test"
             },
             Account = new Domain.Entities.Account
             {
                 Name = "test"
             }
         })
     });
 }
        public async Task Then_The_Query_Is_Validated(
            GetAccountLegalEntitiesForProviderQuery query,
            [Frozen] Mock <IProviderPermissionService> service,
            [Frozen] Mock <IValidator <GetAccountLegalEntitiesForProviderQuery> > validator,
            GetAccountLegalEntitiesForProviderQueryHandler handler)
        {
            //Arrange
            validator.Setup(x => x.ValidateAsync(query)).ReturnsAsync(new ValidationResult
            {
                ValidationDictionary = new Dictionary <string, string>()
            });
            SetupProviderPermissionService(query, service);

            //Act
            await handler.Handle(query, CancellationToken.None);

            //Act
            validator.Verify(x => x.ValidateAsync(query), Times.Once);
        }
        public async Task Then_The_Service_Is_Called_With_The_Supplied_ProviderId_And_Results_Returned_In_The_Response(
            GetAccountLegalEntitiesForProviderQuery query,
            [Frozen] Mock <IProviderPermissionService> service,
            [Frozen] Mock <IValidator <GetAccountLegalEntitiesForProviderQuery> > validator,
            GetAccountLegalEntitiesForProviderQueryHandler handler)
        {
            //Arrange
            validator.Setup(x => x.ValidateAsync(query)).ReturnsAsync(new ValidationResult
            {
                ValidationDictionary = new Dictionary <string, string>()
            });
            ;
            SetupProviderPermissionService(query, service);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            service.Verify(x => x.GetPermissionsByProviderId(query.ProviderId), Times.Once);
            Assert.IsNotNull(actual.ProviderPermissions);
        }