示例#1
0
        public async Task CreateMagisterClassAsync_WithValidRequest_CreatesClass()
        {
            // Arrange
            var input = _fixture.Create <CreateMagisterClassRequest>();
            var validationMessages = _fixture.CreateMany <ValidationMessage>(0);

            _magisterClassValidator
            .Setup(x => x.ValidateRules(input))
            .Returns(validationMessages);

            var expectedMagisterClass = _fixture.Create <MagisterClass>();

            _magisterFileReader
            .Setup(x => x.ReadClass(It.Is <Path>(p => p.Value == input.MagisterFileLocation)))
            .Returns(expectedMagisterClass);

            // Act
            CreateMagisterClassResult result = await _sut.CreateMagisterClassAsync(input);

            // Assert
            result.ClassId.Should().NotBeEmpty();
            result.ValidationMessages.Should().BeEmpty();

            _classRepository
            .Verify(x => x.CreateAsync(It.Is <Class>(x => x.Name.Value == expectedMagisterClass.Name)));
        }
示例#2
0
        public async Task CreateMagisterClassAsync_WithValidationMessages_ReturnsValidationMessages()
        {
            var input = _fixture.Create <CreateMagisterClassRequest>();
            var expectedValidationMessages = _fixture.CreateMany <ValidationMessage>();

            _magisterClassValidator
            .Setup(x => x.ValidateRules(input))
            .Returns(expectedValidationMessages);

            CreateMagisterClassResult result = await _sut.CreateMagisterClassAsync(input);

            result.Should().NotBeNull();
            result.ValidationMessages.Should().BeEquivalentTo(expectedValidationMessages);
        }
        private async Task CreateClassFromFile(IFileInfoWrapper[] files)
        {
            byte             chosenIndex = SharedConsoleFlows.AskForByte("What file should be used?");
            IFileInfoWrapper chosenFile  = await GetFile(files, chosenIndex);

            var request = new CreateMagisterClassRequest
            {
                MagisterFileLocation = chosenFile.FullName
            };
            CreateMagisterClassResult createMagisterClassResponse = await _classController.CreateMagisterClassAsync(request);

            if (createMagisterClassResponse.ValidationMessages.Any())
            {
                SharedConsoleFlows.PrintValidationMessages(createMagisterClassResponse.ValidationMessages);
                await StartAsync();
            }
        }