コード例 #1
0
        public async Task DoesUploadAddCorrectSubstitutionRecord()
        {
            var request = new UploadSubstitutionsCommand
            {
                IpAddress         = MockData.CorrectIpAddress,
                Key               = MockData.CorrectUploadKey,
                SubstitutionsDate = MockData.CorrectDate,
                UploadDateTime    = MockData.CorrectDate,
                Substitutions     = new[]
                {
                    new SubstitutionDto
                    {
                        Absent       = "MockedAbsent1", Lesson = 1, Subject = "MockedSubject1",
                        ClassesNames = new[] { "1b", "2a" }, Groups = "group1,group2", Note = "MockedNote",
                        Cancelled    = true, Room = "MockedRoom"
                    },
                    new SubstitutionDto
                    {
                        Absent = "MockedAbsent2", Lesson = 2, Subject = "MockedSubject2", ClassesNames = new[] { "1b" },
                        Groups = "n/a", Note = "MockedNote2", Substituting = "MockedSubstituting", Room = "MockedRoom"
                    }
                }
            };

            var context       = new FakeDbContext();
            var clients       = new IPlatformClient[0];
            var hangfire      = new Mock <IBackgroundJobClient>();
            var classesParser = new Mock <IClassesParser>();

            classesParser
            .Setup(x => x.Parse(new[] { "1b" }))
            .Returns(new[] { new Class(1, "b") });
            classesParser
            .Setup(x => x.Parse(new[] { "1b", "2a" }))
            .Returns(new[] { new Class(1, "b"), new Class(2, "a") });

            var handler = new UploadSubstitutionsCommandHandler(context, clients, hangfire.Object, classesParser.Object);
            await handler.Handle(request, CancellationToken.None);

            var expected = new SubstitutionsRecord {
                UploadDateTime    = MockData.CorrectDate,
                SubstitutionsDate = MockData.CorrectDate,
                Substitutions     = new[]
                {
                    new Substitution
                    {
                        Teacher = "MockedAbsent1", Lesson = 1, Subject = "MockedSubject1", Groups = "group1,group2",
                        Note    = "MockedNote", Cancelled = true, Room = "MockedRoom",
                        Classes = new[]
                        {
                            await context.Classes.FirstOrDefaultAsync(x => x.Year == 1 && x.Section == "b"),
                            await context.Classes.FirstOrDefaultAsync(x => x.Year == 2 && x.Section == "a")
                        }
                    },
                    new Substitution
                    {
                        Teacher = "MockedAbsent2", Lesson = 2, Subject = "MockedSubject2", Groups = "n/a",
                        Note    = "MockedNote2", Substituting = "MockedSubstituting", Room = "MockedRoom",
                        Classes = new[]
                        {
                            await context.Classes.FirstOrDefaultAsync(x => x.Year == 1 && x.Section == "b")
                        }
                    }
                }
            };

            var actual = await context.SubstitutionsRecords.FirstOrDefaultAsync();

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #2
0
        public async Task DoesUploadWorksCorrectly()
        {
            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"
                    },
                    new SubstitutionDto
                    {
                        Cancelled    = true,
                        ClassesNames = new [] { "I a", "II b" },
                        Groups       = "Cała klasa",
                        Lesson       = 2,
                        Room         = "304",
                        Subject      = "matematyka",
                        Absent       = "sample teacher 3"
                    },
                },
                UploadDateTime    = MockData.CorrectDate,
                SubstitutionsDate = MockData.CorrectDate
            };
            var fakeDbContext       = new FakeDbContext();
            var backgroundJobClient = new Mock <IBackgroundJobClient>();
            var sampleClient        = new Mock <IPlatformClient>();

            sampleClient.Setup(x => x.PlatformId).Returns("DebugMessageService");

            var classParser = new Mock <IClassesParser>();

            classParser.Setup(classparser => classparser.Parse(It.IsAny <IEnumerable <string> >())).Returns(
                (IEnumerable <string> x) =>
            {
                if (x.Contains("I a") & x.Contains("III c"))
                {
                    return new[] { new Class(1, "a"), new Class(3, "c") }
                }
                ;
                else
                {
                    return new[] { new Class(1, "a"), new Class(2, "b") }
                };
            });

            var handler = new UploadSubstitutionsCommandHandler(fakeDbContext, new [] { sampleClient.Object }, backgroundJobClient.Object, classParser.Object);

            await handler.Handle(request, CancellationToken.None);

            backgroundJobClient.Verify(x => x.Create(It.Is <Job>(job => job.Method.Name == "SendMessage"), It.IsAny <IState>()));
        }
コード例 #3
0
        public async Task DoesNewlyCreatedClassesAreNotDuplicated()
        {
            var request = new UploadSubstitutionsCommand
            {
                IpAddress     = MockData.CorrectIpAddress,
                Key           = MockData.CorrectUploadKey,
                Substitutions = new []
                {
                    new SubstitutionDto
                    {
                        Cancelled    = false,
                        ClassesNames = new [] { "II a", "III c" },
                        Groups       = "Cała klasa",
                        Lesson       = 3,
                        Room         = "204",
                        Subject      = "j. Polski",
                        Substituting = "sample teacher 1",
                        Absent       = "sample teacher 2"
                    },
                    new SubstitutionDto
                    {
                        Cancelled    = true,
                        ClassesNames = new [] { "II a", "II b" },
                        Groups       = "Cała klasa",
                        Lesson       = 2,
                        Room         = "304",
                        Subject      = "matematyka",
                        Absent       = "sample teacher 3"
                    },
                },
                UploadDateTime    = MockData.CorrectDate,
                SubstitutionsDate = MockData.CorrectDate
            };
            var fakeDbContext       = new FakeDbContext();
            var backgroundJobClient = new Mock <IBackgroundJobClient>();
            var sampleClient        = new Mock <IPlatformClient>();

            sampleClient.Setup(x => x.PlatformId).Returns("DebugMessageService");

            var classParser = new Mock <IClassesParser>();

            classParser.Setup(classesParser => classesParser.Parse(It.IsAny <IEnumerable <string> >())).Returns(
                (IEnumerable <string> x) =>
            {
                var array = x.ToArray();
                if (array.Contains("II a") & array.Contains("III c"))
                {
                    return new[] { new Class(2, "a"), new Class(3, "c") }
                }
                ;
                else
                {
                    return new[] { new Class(2, "a"), new Class(2, "b") }
                };
            });

            var handler = new UploadSubstitutionsCommandHandler(fakeDbContext, new [] { sampleClient.Object }, backgroundJobClient.Object, classParser.Object);

            await handler.Handle(request, CancellationToken.None);

            fakeDbContext.Classes.Should()
            .HaveCount(4)
            .And
            .Contain(new[]
            {
                new Class(1, "a"),
                new Class(2, "a"),
                new Class(3, "c"),
                new Class(2, "b"),
            });
        }