Example #1
0
        public void ModelListIncludesEmpty()
        {
            // Arrange
            var channelId      = Guid.NewGuid();
            var organizationId = Guid.NewGuid();

            channelServiceMockSetup.Setup(c => c.GetServiceChannelByIdSimple(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns((Guid id, bool onlyPublished) =>
            {
                if (!id.IsAssigned())
                {
                    return(null);
                }
                return(new VmOpenApiServiceChannel()
                {
                    Id = id,
                    IsVisibleForAll = false,
                    OrganizationId = organizationId
                });
            });
            var list = new List <Guid>()
            {
                Guid.Empty, channelId
            };
            var validator = new ServiceChannelIdListValidator(list, channelService, UserRoleEnum.Eeva); // new List <Guid> { organizationId });

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

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(Guid.Empty, true), Times.Once());
            channelServiceMockSetup.Verify(x => x.GetServiceChannelByIdSimple(channelId, true), Times.Once());
        }
Example #2
0
        public void ModelIsNull()
        {
            // Arrange
            var validator = new ServiceChannelIdListValidator(null, channelService, UserRoleEnum.Eeva);

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

            // Assert
            controller.ModelState.IsValid.Should().BeTrue();
        }
Example #3
0
        public void ModelListIncludesChannelForOtherOrganization()
        {
            // Arrange
            var channelId        = Guid.NewGuid();
            var invalidChannelId = Guid.NewGuid();
            var organizationId   = Guid.NewGuid();

            channelServiceMockSetup.Setup(c => c.GetServiceChannelByIdSimple(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns((Guid id, bool onlyPublished) =>
            {
                if (!id.IsAssigned())
                {
                    return(null);
                }
                return(new VmOpenApiServiceChannel()
                {
                    Id = id,
                    IsVisibleForAll = false,
                    OrganizationId = id == channelId ? organizationId : Guid.NewGuid(),     // Returned organization is different than user organization if the channel id is invalid
                    Security = new VmSecurityOwnOrganization {
                        IsOwnOrganization = false
                    }
                });
            });

            var list = new List <Guid>()
            {
                channelId, invalidChannelId
            };
            var validator = new ServiceChannelIdListValidator(list, channelService, UserRoleEnum.Pete);

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

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