public static ContainerBuilder AddUnitOfWork(this ContainerBuilder builder, Action <UnitOfWorkBuilder> optionsAction = null)
        {
            builder.RegisterType <UnitOfWorkProvider>().SingleInstance().AsImplementedInterfaces();
            builder.RegisterType <UnitOfWork.EntityFramework.EntityFrameworkUnitOfWork>();

            var unitOfWorkBuilder = new UnitOfWorkBuilder(builder);

            optionsAction?.Invoke(unitOfWorkBuilder);
            builder.RegisterInstance(unitOfWorkBuilder);

            return(builder);
        }
示例#2
0
        public async Task Should_Get_Photo()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();
            var photo      = GetPhoto();
            await unitOfWork.Photos.Add(photo);

            var photoService = new PhotoServiceBuilder()
                               .WithUnitOfWork(unitOfWork).Build();
            var savedPhoto = await photoService.GetPhoto("1234");

            savedPhoto.Should().NotBeNull();
            savedPhoto.Should().Be(photo);
        }
示例#3
0
        public async Task Creator_Should_Get_Album()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var albumService = new AlbumServiceBuild()
                               .WithUnitOfWork(unitOfWork)
                               .Build();
            var user  = GetUser();
            var album = GetAlbum(user);
            await unitOfWork.Albums.Add(album);

            var albums = await albumService.GetAlbums(user);

            albums.Should().Contain(album);
        }
示例#4
0
        public async Task Create_Album_Should_Save()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var albumService = new AlbumServiceBuild()
                               .WithUnitOfWork(unitOfWork)
                               .Build();
            var user  = GetUser();
            var album = await albumService.CreateAlbum(user, "albumName");

            var savedAlbum = await unitOfWork.Albums.GetFirst(x => x.Name == "albumName");

            album.Should().NotBeNull();
            album.Should().Equals(savedAlbum);
        }
示例#5
0
        public async Task Should_Delete_From_Ftp()
        {
            var ftpService = A.Fake <IFtpService>();
            var unitOfWork = new UnitOfWorkBuilder().Build();
            var user       = GetUser();
            var photo      = GetPhoto();
            await unitOfWork.Photos.Add(photo);

            var photoService = new PhotoServiceBuilder()
                               .WithFtpService(ftpService)
                               .WithUnitOfWork(unitOfWork)
                               .WithPermissionsService(new AllPermissionsGrantedService()).Build();
            var successfullyDeleted = await photoService.DeletePhoto(photo.PhotoId, "1234", user);

            successfullyDeleted.Should().BeTrue();
            A.CallTo(() => ftpService.DeletePhoto(photo)).MustHaveHappened();
        }
示例#6
0
        public async Task Should_Get_Album_By_Id()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var albumService = new AlbumServiceBuild()
                               .WithUnitOfWork(unitOfWork)
                               .Build();
            var user  = GetUser();
            var album = GetAlbum(user);

            album.AlbumId = "1234";
            await unitOfWork.Albums.Add(album);

            var savedAlbum = await albumService.GetAlbum("1234");

            savedAlbum.Should().NotBeNull();
            savedAlbum.Should().Be(album);
        }
示例#7
0
        public async Task Should_Delete_From_Db()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();
            var user       = GetUser();
            var photo      = GetPhoto();
            await unitOfWork.Photos.Add(photo);

            var photoService = new PhotoServiceBuilder()
                               .WithUnitOfWork(unitOfWork)
                               .WithPermissionsService(new AllPermissionsGrantedService()).Build();

            var successfullyDeleted = await photoService.DeletePhoto(photo.PhotoId, "1234", user);

            successfullyDeleted.Should().BeTrue();
            var photos = await unitOfWork.Photos.GetAll();

            photos.Should().BeEmpty();
        }
示例#8
0
        public async Task UserService_Should_ReSend_Email_To_Invited_Users()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var emailService = A.Fake <IEmailService>();

            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .WithEmailService(emailService)
                              .Build();

            var user = GetUser();

            user.InvitationSent = true;
            user.Password       = "******";
            await unitOfWork.Users.Add(user);

            await userService.SendAgainEmailToUsers();

            A.CallTo(() => emailService.SendAccountCreationEmail(user, "pwd")).MustHaveHappened();
        }
示例#9
0
        public async Task UserService_Should_Return_ByEmail()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();

            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .Build();
            var user = GetUser();

            user.Password = "******";
            user.UserId   = "userId";

            await unitOfWork.Users.Add(user);

            var savedUser = await userService.GetUserFromEmail(user.Email);

            savedUser.Should().NotBeNull();
            savedUser.Password.Should().Be("code");
            savedUser.UserId.Should().Be("userId");
        }
示例#10
0
        public async Task Accepting_Invitation_Should_Be_Flagged()
        {
            var unitOfWork  = new UnitOfWorkBuilder().Build();
            var datetime    = DateTime.UtcNow;
            var userService = new UserServiceBuilder()
                              .WithDateTime(datetime)
                              .WithUnitOfWork(unitOfWork)
                              .Build();
            var user = GetUser();

            user.Password = "******";
            await unitOfWork.Users.Add(user);

            await userService.AcceptInvitation("code");

            var savedUser = await unitOfWork.Users.GetFirst(x => x.Email == user.Email);

            savedUser.InvitationAccepted.Should().BeTrue();
            savedUser.AcceptingDate.Should().Be(datetime);
        }
示例#11
0
        public async Task Invited_User_Should_Be_Flagged()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var emailService = A.Fake <IEmailService>();
            var datetime     = DateTime.UtcNow;

            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .WithEmailService(emailService)
                              .WithDateTime(datetime)
                              .Build();

            var user = GetUser();
            await unitOfWork.Users.Add(user);

            await userService.SendEmailToUsers();

            var savedUser = await unitOfWork.Users.GetFirst(x => x.Email == user.Email);

            savedUser.InvitationSent.Should().BeTrue();
            savedUser.SendingDate.Should().Be(datetime);
        }
示例#12
0
        public async Task Creator_Should_Add_Follower()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var albumService = new AlbumServiceBuild()
                               .WithUnitOfWork(unitOfWork)
                               .Build();
            var user  = GetUser();
            var album = GetAlbum(user);

            album.AlbumId = "1234";
            await unitOfWork.Albums.Add(album);

            var follower          = GetFollower();
            var successfullyAdded = await albumService.AddFollower("1234", follower, user);

            var savedAlbum = await unitOfWork.Albums.GetFirst(x => x.AlbumId == "1234");

            successfullyAdded.Should().BeTrue();
            savedAlbum.Followers.Should().ContainSingle();
            savedAlbum.Followers.Should().Contain(follower);
        }
示例#13
0
        public async Task Admin_Should_Not_Add_Admin()
        {
            var unitOfWork   = new UnitOfWorkBuilder().Build();
            var albumService = new AlbumServiceBuild()
                               .WithUnitOfWork(unitOfWork)
                               .Build();
            var user  = GetUser();
            var album = GetAlbum(user);

            album.AlbumId = "1234";
            await unitOfWork.Albums.Add(album);

            var admin = GetAdmin();
            await albumService.AddAdmin("1234", admin, user);

            var successfullyAdded = await albumService.AddAdmin("1234", user, admin);

            var savedAlbum = await unitOfWork.Albums.GetFirst(x => x.AlbumId == "1234");

            successfullyAdded.Should().BeFalse();
            savedAlbum.Admins.Should().ContainSingle();
            savedAlbum.Admins.Should().NotContain(user);
        }
示例#14
0
        public async Task User_Should_Not_Subscribe_With_Same_Email()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();

            var passwordService = A.Fake <IPasswordService>();

            A.CallTo(() => passwordService.GenerateRandomPassword()).Returns(("hash", "salt"));

            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .WithPasswordService(passwordService)
                              .Build();

            var user = new User {
                Email = "*****@*****.**", FirstName = "John", LastName = "Doe"
            };
            var user2 = new User {
                Email = "*****@*****.**", FirstName = "Jane", LastName = "Doe"
            };
            var users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(0);
            await userService.RegisterMembers(new List <User> {
                user
            });

            users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(1);
            await userService.RegisterMembers(new List <User> {
                user2
            });

            users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(1);
        }
        public async Task Like_Should_Be_Stored()
        {
            var photoService = A.Fake <IPhotoService>();
            var photo        = GetPhoto();
            var user         = GetUser();
            var guid         = Guid.NewGuid();
            var unitOfWork   = new UnitOfWorkBuilder().Build();

            A.CallTo(() => photoService.GetPhoto(photo.PhotoId)).Returns(photo);
            var reactionService = new ReactionServiceBuilder()
                                  .WithGuid(guid)
                                  .WithPhotoService(photoService)
                                  .WithUnitOfWork(unitOfWork)
                                  .WithPermissionsService(new AllPermissionsGrantedService())
                                  .Build();
            var like = await reactionService.LikePhoto("1234", "albumId", user);

            var storedLike = await unitOfWork.Likes.GetAll(x => x.ReactionId == guid.ToString());

            storedLike.Should().NotBeNull();
            storedLike.Should().NotBeEmpty();
            storedLike.Should().ContainSingle();
            storedLike.Should().Contain(like);
        }
 public void SetUp()
 {
     this.uow = UnitOfWorkBuilder.Build(ENDPOINTS.READWRITE_URI);
 }