コード例 #1
0
        public async Task DoesValidatorPreventUploadWithInvalidKey()
        {
            var config    = new ConfigurationBuilder().AddInMemoryCollection(new[] { new KeyValuePair <string, string>("UploadKey", "sample-key") }).Build();
            var validator = new UploadSubstitutionsCommandValidator(config, new FakeDbContext());

            var request = new UploadSubstitutionsCommand
            {
                IpAddress         = MockData.CorrectIpAddress,
                SubstitutionsDate = MockData.CorrectDate,
                UploadDateTime    = MockData.CorrectDate,
                Key           = "invalid-key",
                Substitutions = new []
                {
                    new SubstitutionDto
                    {
                        Cancelled    = false,
                        ClassesNames = new[] { "I a", "III c" },
                        Groups       = "Cała klasa",
                        Lesson       = 3,
                        Room         = "204",
                        Subject      = "j. Polski",
                        Substituting = "sample teacher 1",
                        Absent       = "sample teacher 2"
                    }
                }
            };

            var result = await validator.ValidateAsync(request, CancellationToken.None);

            result.IsValid.Should().BeFalse();
            result.Errors.Should().HaveCount(1).And.ContainSingle(x => x.ErrorCode == "PredicateValidator" && x.ErrorMessage == "Key must be a correct key from configuration.");
        }
コード例 #2
0
        public async Task DoesValidatorAllowValidRequest()
        {
            var config    = new ConfigurationBuilder().AddInMemoryCollection(new[] { new KeyValuePair <string, string>("UploadKey", "sample-key") }).Build();
            var validator = new UploadSubstitutionsCommandValidator(config, new FakeDbContext());

            var request = new UploadSubstitutionsCommand
            {
                IpAddress     = MockData.CorrectIpAddress,
                Key           = MockData.CorrectUploadKey,
                Substitutions = new []
                {
                    new SubstitutionDto
                    {
                        Cancelled    = false,
                        ClassesNames = new[] { "I a", "III c" },
                        Groups       = "Cała klasa",
                        Lesson       = 3,
                        Room         = "204",
                        Subject      = "j. Polski",
                        Substituting = "sample teacher 1",
                        Absent       = "sample teacher 2"
                    }
                },
                UploadDateTime    = MockData.CorrectDate,
                SubstitutionsDate = MockData.CorrectDate
            };

            var result = await validator.ValidateAsync(request, CancellationToken.None);

            result.IsValid.Should().BeTrue();
            result.Errors.Should().HaveCount(0);
        }
コード例 #3
0
        public async Task DoesValidatorPreventUploadOfInvalidSubstitutionsPlan()
        {
            var config    = new ConfigurationBuilder().AddInMemoryCollection(new[] { new KeyValuePair <string, string>("UploadKey", "sample-key") }).Build();
            var validator = new UploadSubstitutionsCommandValidator(config, new FakeDbContext());

            var request = new UploadSubstitutionsCommand
            {
                IpAddress         = MockData.CorrectIpAddress,
                Key               = MockData.CorrectUploadKey,
                SubstitutionsDate = MockData.CorrectDate,
                UploadDateTime    = MockData.CorrectDate,
                Substitutions     = ArraySegment <SubstitutionDto> .Empty
            };

            var result = await validator.ValidateAsync(request, CancellationToken.None);

            result.IsValid.Should().BeFalse();
            result.Errors.Should().HaveCount(1).And.ContainSingle(x => x.ErrorCode == "NotEmptyValidator" && x.ErrorMessage == "Substitutions cannot be empty.");
        }