public async Task Given_AddData_When_UserDoesNotExistAndFileTypeIsInput_Then_ShouldSucceed()
        {
            var command   = GetAddDataCommand(FileType.Input);
            var user      = UserFactory.GetUser();
            var modelFile = DataFileFactory.GetModelFile(user);

            userServiceMock.Setup(service => service.GetByUsername(It.IsAny <string>()))
            .ReturnsAsync(Maybe <User> .None);
            userServiceMock.Setup(service => service.AddUser(It.IsAny <AddUserCommand>()))
            .ReturnsAsync(Result.Success(user));
            dataFileReadRepositoryMock.Setup(repository => repository.Find(It.IsAny <Expression <Func <DataFile, bool> > >()))
            .ReturnsAsync(new List <DataFile> {
                modelFile
            });
            fileStorageServiceMock.Setup(service => service.SaveFile(It.IsAny <SaveFileCommand>()))
            .Returns(Task.CompletedTask);
            dataFileWriteRepositoryMock.Setup(repository => repository.Create(It.IsAny <DataFile>()))
            .Returns(Task.CompletedTask);
            dataFileWriteRepositoryMock.Setup(repository => repository.Commit())
            .Returns(Task.CompletedTask);

            var result = await SystemUnderTest.AddData(command);

            result.IsSuccess.Should().BeTrue();
        }
Exemple #2
0
        public async Task Given_AddData_Then_Should_ReturnCreatedAtActionResult()
        {
            var model = BuildModel();

            SetupExtractUsername();
            storageServiceMock.Setup(service => service.AddData(It.IsAny <AddDataCommand>()))
            .ReturnsAsync(Result.Success());

            var result = await SystemUnderTest.AddData(model);

            result.Should().BeOfType <CreatedAtActionResult>();
        }
        public async Task Given_AddData_When_UserDoesNotExistAndFileTypeIsModel_Then_ShouldFail()
        {
            var command = GetAddDataCommand(FileType.Model);
            var user    = UserFactory.GetUser();

            userServiceMock.Setup(service => service.GetByUsername(It.IsAny <string>()))
            .ReturnsAsync(Maybe <User> .None);
            userServiceMock.Setup(service => service.AddUser(It.IsAny <AddUserCommand>()))
            .ReturnsAsync(Result.Success(user));
            dataFileReadRepositoryMock.Setup(repository => repository.Find(It.IsAny <Expression <Func <DataFile, bool> > >()))
            .ReturnsAsync(new List <DataFile>());

            var result = await SystemUnderTest.AddData(command);

            result.IsFailure.Should().BeTrue();
        }