Exemplo n.º 1
0
        public void SetUp()
        {
            _producer  = CreateEntry.Producer();
            _vocalist  = CreateEntry.Vocalist(name: "Hatsune Miku");
            _vocalist2 = CreateEntry.Vocalist(name: "Rin");

            _album      = CreateEntry.Album(id: 39, name: "Synthesis");
            _repository = new FakeAlbumRepository(_album);
            foreach (var name in _album.Names)
            {
                Save(name);
            }
            _user         = CreateEntry.User(1, "Miku");
            _user.GroupId = UserGroupId.Moderator;
            _user2        = CreateEntry.User(2, "Luka");
            Save(_user, _user2);
            Save(_producer, _vocalist, _vocalist2);

            _song  = Save(CreateEntry.Song(name: "Nebula"));
            _song2 = Save(CreateEntry.Song(name: "Anger"));
            _song3 = Save(CreateEntry.Song(name: "Resistance"));

            _permissionContext = new FakePermissionContext(_user);
            var entryLinkFactory = new EntryAnchorFactory("http://test.vocadb.net");

            _newAlbumContract = new CreateAlbumContract
            {
                DiscType = DiscType.Album,
                Names    = new[] {
                    new LocalizedStringContract("Another Dimensions", ContentLanguageSelection.English)
                },
                Artists = new[] {
                    new ArtistContract(_producer, ContentLanguagePreference.Default),
                    new ArtistContract(_vocalist, ContentLanguagePreference.Default),
                }
            };

            _imagePersister = new InMemoryImagePersister();
            _mailer         = new FakeUserMessageMailer();
            _queries        = new AlbumQueries(
                _repository,
                _permissionContext,
                entryLinkFactory,
                _imagePersister,
                _imagePersister,
                _mailer,
                new FakeUserIconFactory(),
                new EnumTranslations(),
                new FakePVParser(),
                new FollowedArtistNotifier(new FakeEntryLinkFactory(), new FakeUserMessageMailer(), new EnumTranslations(), new EntrySubTypeNameFactory()),
                new InMemoryImagePersister(),
                new FakeObjectCache(),
                new FakeDiscordWebhookNotifier());
        }
Exemplo n.º 2
0
        public AlbumContract Create(CreateAlbumContract contract)
        {
            ParamIs.NotNull(() => contract);

            if (contract.Names == null || !contract.Names.Any())
            {
                throw new ArgumentException("Album needs at least one name", "contract");
            }

            VerifyManageDatabase();

            return(repository.HandleTransaction(ctx => {
                ctx.AuditLogger.SysLog(string.Format("creating a new album with name '{0}'", contract.Names.First().Value));

                var album = new Album {
                    DiscType = contract.DiscType
                };

                album.Names.Init(contract.Names, album);

                ctx.Save(album);

                foreach (var artistContract in contract.Artists)
                {
                    var artist = ctx.OfType <Artist>().Load(artistContract.Id);
                    if (!album.HasArtist(artist))
                    {
                        ctx.OfType <ArtistForAlbum>().Save(ctx.OfType <Artist>().Load(artist.Id).AddAlbum(album));
                    }
                }

                album.UpdateArtistString();
                var archived = Archive(ctx, album, AlbumArchiveReason.Created);
                ctx.Update(album);

                ctx.AuditLogger.AuditLog(string.Format("created album {0} ({1})", entryLinkFactory.CreateEntryLink(album), album.DiscType));
                AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), album, EntryEditEvent.Created, archived);

                new FollowedArtistNotifier().SendNotifications(ctx, album, album.ArtistList, PermissionContext.LoggedUser,
                                                               entryLinkFactory, mailer, enumTranslations);

                return new AlbumContract(album, PermissionContext.LanguagePreference);
            }));
        }
Exemplo n.º 3
0
        public async Task <AlbumContract> Create(CreateAlbumContract contract)
        {
            ParamIs.NotNull(() => contract);

            if (contract.Names == null || !contract.Names.Any())
            {
                throw new ArgumentException("Album needs at least one name", "contract");
            }

            VerifyManageDatabase();

            return(await _repository.HandleTransactionAsync(async ctx =>
            {
                ctx.AuditLogger.SysLog($"creating a new album with name '{contract.Names.First().Value}'");

                var album = new Album {
                    DiscType = contract.DiscType
                };

                album.Names.Init(contract.Names, album);

                await ctx.SaveAsync(album);

                foreach (var artistContract in contract.Artists)
                {
                    var artist = await ctx.LoadAsync <Artist>(artistContract.Id);
                    if (!album.HasArtist(artist))
                    {
                        await ctx.SaveAsync(artist.AddAlbum(album));
                    }
                }

                album.UpdateArtistString();
                var archived = await ArchiveAsync(ctx, album, AlbumArchiveReason.Created);
                await ctx.UpdateAsync(album);

                await ctx.AuditLogger.AuditLogAsync($"created album {_entryLinkFactory.CreateEntryLink(album)} ({album.DiscType})");
                await AddEntryEditedEntryAsync(ctx.OfType <ActivityEntry>(), album, EntryEditEvent.Created, archived);

                await _followedArtistNotifier.SendNotificationsAsync(ctx, album, album.ArtistList, PermissionContext.LoggedUser);

                return new AlbumContract(album, PermissionContext.LanguagePreference);
            }));
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            producer  = CreateEntry.Producer();
            vocalist  = CreateEntry.Vocalist(name: "Hatsune Miku");
            vocalist2 = CreateEntry.Vocalist(name: "Rin");

            album      = CreateEntry.Album(id: 39, name: "Synthesis");
            repository = new FakeAlbumRepository(album);
            foreach (var name in album.Names)
            {
                Save(name);
            }
            user         = CreateEntry.User(1, "Miku");
            user.GroupId = UserGroupId.Moderator;
            user2        = CreateEntry.User(2, "Luka");
            Save(user, user2);
            Save(producer, vocalist, vocalist2);

            song  = Save(CreateEntry.Song(name: "Nebula"));
            song2 = Save(CreateEntry.Song(name: "Anger"));
            song3 = Save(CreateEntry.Song(name: "Resistance"));

            permissionContext = new FakePermissionContext(user);
            var entryLinkFactory = new EntryAnchorFactory("http://test.vocadb.net");

            newAlbumContract = new CreateAlbumContract {
                DiscType = DiscType.Album,
                Names    = new[] {
                    new LocalizedStringContract("Another Dimensions", ContentLanguageSelection.English)
                },
                Artists = new[] {
                    new ArtistContract(producer, ContentLanguagePreference.Default),
                    new ArtistContract(vocalist, ContentLanguagePreference.Default),
                }
            };

            imagePersister = new InMemoryImagePersister();
            mailer         = new FakeUserMessageMailer();
            queries        = new AlbumQueries(repository, permissionContext, entryLinkFactory, imagePersister, imagePersister, mailer,
                                              new FakeUserIconFactory(), new EnumTranslations(), new FakePVParser());
        }
Exemplo n.º 5
0
        public AlbumContract Create(CreateAlbumContract contract)
        {
            ParamIs.NotNull(() => contract);

            if (contract.Names == null || !contract.Names.Any())
            {
                throw new ArgumentException("Album needs at least one name", "contract");
            }

            VerifyManageDatabase();

            return(HandleTransaction(session => {
                SysLog(string.Format("creating a new album with name '{0}'", contract.Names.First().Value));

                var album = new Album {
                    DiscType = contract.DiscType
                };

                album.Names.Init(contract.Names, album);

                session.Save(album);

                foreach (var artist in contract.Artists)
                {
                    session.Save(session.Load <Artist>(artist.Id).AddAlbum(album));
                }

                album.UpdateArtistString();
                Archive(session, album, AlbumArchiveReason.Created);
                session.Update(album);

                AuditLog(string.Format("created {0}", EntryLinkFactory.CreateEntryLink(album)), session);
                AddEntryEditedEntry(session, album, EntryEditEvent.Created);

                return new AlbumContract(album, PermissionContext.LanguagePreference);
            }));
        }