public void TestSpaceCreation(string stringUserId)
        {
            var userId = Guid.Parse(stringUserId);

            var user = new ApplicationUser()
            {
                Id = userId
            };


            //setup mock
            var mockSpaceRepository = new Mock <Repository <Space> >();
            var mockUserRepository  = new Mock <Repository <ApplicationUser> >();

            mockUserRepository
            .Setup(n => n.GetByID(It.IsAny <Guid>()))
            .Returns(user);

            mockSpaceRepository
            .Setup(n => n.Insert(It.IsAny <Space>()));

            _spaceService.Create(userId);
        }
Beispiel #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISpaceRepository>();
            var model = new ApiSpaceRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Space>())).Returns(Task.FromResult(new Space()));
            var service = new SpaceService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLSpaceMapperMock,
                                           mock.DALMapperMockFactory.DALSpaceMapperMock);

            CreateResponse <ApiSpaceResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Space>()));
        }
Beispiel #3
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ISpaceService, ISpaceRepository>();

            var model = new ApiSpaceServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Space>())).Returns(Task.FromResult(new Space()));
            var service = new SpaceService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALSpaceMapperMock,
                                           mock.DALMapperMockFactory.DALSpaceSpaceFeatureMapperMock);

            CreateResponse <ApiSpaceServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Space>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpaceCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Beispiel #4
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISpaceService, ISpaceRepository>();
            var model         = new ApiSpaceServerRequestModel();
            var validatorMock = new Mock <IApiSpaceServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new SpaceService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           validatorMock.Object,
                                           mock.DALMapperMockFactory.DALSpaceMapperMock,
                                           mock.DALMapperMockFactory.DALSpaceSpaceFeatureMapperMock);

            CreateResponse <ApiSpaceServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpaceCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }