Ejemplo n.º 1
0
        public void ModelAndUserOrganizationSetAndChannelExistsStateValid(bool channelIsVisibleForAll, bool channelOrganizationIsSameAsUserOrganization)
        {
            // Arrange
            var channelId      = Guid.NewGuid();
            var organizationId = Guid.NewGuid();

            channelServiceMockSetup.Setup(c => c.GetServiceChannelByIdSimple(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns(new VmOpenApiServiceChannel()
            {
                Id = channelId,
                IsVisibleForAll = channelIsVisibleForAll,
                OrganizationId  = channelOrganizationIsSameAsUserOrganization ? organizationId : Guid.NewGuid(),
                Security        = new VmSecurityOwnOrganization {
                    IsOwnOrganization = channelOrganizationIsSameAsUserOrganization
                }
            });
            var validator = new ServiceChannelIdValidator(channelId, channelService, UserRoleEnum.Eeva, "PropertyName");//new List<Guid> { organizationId });

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeTrue();
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(channelId, true), Times.Once());
        }
Ejemplo n.º 2
0
        public void ModelIsEmpty()
        {
            // Arrange
            var validator = new ServiceChannelIdValidator(Guid.Empty, channelService, UserRoleEnum.Eeva, "PropertyName");

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(Guid.Empty, true), Times.Once());
        }
Ejemplo n.º 3
0
        public void ModelSetAndChannelDoesNotExist()
        {
            // Arrange
            var channelId = Guid.NewGuid();

            channelServiceMockSetup.Setup(c => c.GetServiceChannelByIdSimple(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns((VmOpenApiServiceChannel)null);
            var validator = new ServiceChannelIdValidator(channelId, channelService, UserRoleEnum.Eeva, "PropertyName");

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(channelId, true), Times.Once());
        }
Ejemplo n.º 4
0
        public void ModelAndUserOrganizationSetAndChannelExistsStateInValid()
        {
            // Arrange
            var channelId = Guid.NewGuid();

            channelServiceMockSetup.Setup(c => c.GetServiceChannelByIdSimple(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns(new VmOpenApiServiceChannel()
            {
                Id = channelId,
                IsVisibleForAll = false,
                OrganizationId  = Guid.NewGuid(),    // Returned organization is different than user organization
                Security        = new VmSecurityOwnOrganization {
                    IsOwnOrganization = false
                }
            });
            var validator = new ServiceChannelIdValidator(channelId, channelService, UserRoleEnum.Pete, "PropertyName");// new List<Guid> { Guid.NewGuid() }); // User organization is different than channel organization.

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(channelId, true), Times.Once());
        }