Exemple #1
0
        public void Execute_WithoutCode_Music()
        {
            var domainId = Guid.NewGuid();
            var domain   = Builder <Domain> .CreateNew()
                           .With(x => x.Id, domainId)
                           .Build();

            var mediaServices = Builder <MediaService> .CreateListOfSize(1).Build().ToList();

            var argument = Builder <CreateLinkArgument> .CreateNew()
                           .With(x => x.Link, Builder <LinkModel> .CreateNew()
                                 .With(x => x.Code, null)
                                 .With(x => x.DomainId, domainId)
                                 .With(x => x.MediaType, MediaType.Music)
                                 .Build())
                           .With(x => x.TicketDestinations, null)
                           .With(x => x.MusicDestinations, new Dictionary <string, List <DestinationModel> >()
            {
                {
                    "all",
                    Builder <DestinationModel> .CreateListOfSize(3)
                    .TheFirst(1)
                    .With(x => x.MediaServiceId, mediaServices.First().Id)
                    .Build().ToList()
                }
            })
                           .Build();

            _domainRepository.Expect(x => x.GetDomain(Arg <Guid> .Is.Equal(domainId))).Return(domain);
            _storageService.Expect(x => x.GetFileList(Arg <string> .Is.Equal(domain.Name), Arg <string> .Is.Anything)).Return(Enumerable.Empty <string>().ToList());

            _mediaServiceRepository.Expect(x => x.GetMediaServices()).Return(mediaServices.AsQueryable());
            _linkRepository.Expect(x =>
                                   x.CreateLink(Arg <Repository.Entities.Link> .Matches(entity =>
                                                                                        entity.DomainId == domainId &&
                                                                                        entity.MediaType == argument.Link.MediaType)))
            .Return(null)
            .WhenCalled(x =>
            {
                x.ReturnValue = (Repository.Entities.Link)x.Arguments[0];
            });

            _storageService.Expect(x =>
                                   x.Save(Arg <string> .Matches(path => path.StartsWith(domain.Name) && path.EndsWith("/general.json")),
                                          Arg <StorageModel> .Matches(st =>
                                                                      st.Destinations.ContainsKey("all") &&
                                                                      st.Destinations["all"].Count == mediaServices.Count)));

            var result = _createLinkCommand.Execute(argument);

            Assert.IsTrue(result.IsActive);
            Assert.AreEqual(domainId, result.DomainId);
            Assert.AreEqual(argument.Link.MediaType, result.MediaType);
            Assert.AreEqual(argument.Link.Title, result.Title);
            Assert.AreEqual(argument.Link.Url, result.Url);
            Assert.IsNull(result.Artists);
        }
        public void Execute_SameCode_Music()
        {
            var domainId = Guid.NewGuid();
            var code     = "test";
            var domain   = Builder <Domain> .CreateNew()
                           .With(x => x.Id, domainId)
                           .Build();

            var mediaServices = Builder <MediaService> .CreateListOfSize(2).Build().ToList();

            var existDbLink = Builder <Repository.Entities.Link> .CreateNew()
                              .With(x => x.IsActive, true)
                              .With(x => x.Code, code)
                              .With(x => x.Domain, domain)
                              .With(x => x.DomainId, domainId)
                              .With(x => x.MediaType, MediaType.Music)
                              .Build();

            var existStorageLink = Builder <StorageModel> .CreateNew()
                                   .With(x => x.MediaType, existDbLink.MediaType)
                                   .With(x => x.Id, existDbLink.Id)
                                   .With(x => x.Title, existDbLink.Title)
                                   .With(x => x.Url, existDbLink.Url)
                                   .With(x => x.TrackingInfo, Builder <TrackingStorageModel> .CreateNew().Build())
                                   .With(x => x.Destinations, new Dictionary <string, List <DestinationStorageModel> >()
            {
                {
                    "all",
                    Builder <DestinationStorageModel> .CreateListOfSize(1)
                    .TheFirst(1)
                    .With(x => x.MediaServiceId, mediaServices.First().Id)
                    .With(x => x.TrackingInfo, Builder <TrackingStorageModel> .CreateNew()
                          .With(x => x.MediaServiceName, mediaServices.First().Name)
                          .With(x => x.Web, "url")
                          .With(x => x.Mobile, null)
                          .Build())
                    .Build().ToList()
                }
            })
                                   .Build();

            var argument = Builder <UpdateLinkArgument> .CreateNew()
                           .With(x => x.Link, Builder <ExtendedLinkModel> .CreateNew()
                                 .With(x => x.Code, existDbLink.Code)
                                 .With(x => x.DomainId, existDbLink.DomainId)
                                 .With(x => x.MediaType, existDbLink.MediaType)
                                 .With(x => x.TicketDestinations, null)
                                 .With(x => x.TrackingInfo, null)
                                 .With(x => x.MusicDestinations, new Dictionary <string, List <DestinationModel> >()
            {
                {
                    "all",
                    Builder <DestinationModel> .CreateListOfSize(3)
                    .All()
                    .Do(x => x.TrackingInfo = Builder <TrackingModel> .CreateNew().Build())
                    .TheFirst(1)
                    .With(x => x.MediaServiceId, mediaServices.First().Id)
                    .TheNext(1)
                    .With(x => x.MediaServiceId, mediaServices.Last().Id)
                    .Build().ToList()
                }
            })
                                 .Build())
                           .Build();

            _linkRepository.Expect(x => x.GetLink(Arg <Guid> .Is.Equal(argument.Link.Id))).Return(existDbLink);
            _domainRepository.Expect(x => x.GetDomain(Arg <Guid> .Is.Equal(domainId))).Return(domain);

            _linkRepository.Expect(x =>
                                   x.UpdateLink(Arg <Repository.Entities.Link> .Matches(entity =>
                                                                                        entity.DomainId == existDbLink.DomainId &&
                                                                                        entity.IsActive &&
                                                                                        entity.MediaType == existDbLink.MediaType &&
                                                                                        entity.Url == argument.Link.Url &&
                                                                                        entity.Title == argument.Link.Title)))
            .Return(null)
            .WhenCalled(x =>
            {
                x.ReturnValue = (Repository.Entities.Link)x.Arguments[0];
            });

            _mediaServiceRepository.Expect(x => x.GetMediaServices()).Return(mediaServices.AsQueryable());

            _storageService.Expect(x => x.Get <StorageModel>(Arg <string> .Matches(path => path.Equals($"{domain.Name}/{code}/general.json"))))
            .Return(existStorageLink);
            _storageService.Expect(x =>
                                   x.Save(Arg <string> .Matches(path => path.Equals($"{domain.Name}/{code}/general.json")),
                                          Arg <StorageModel> .Matches(st =>
                                                                      st.Destinations.ContainsKey("all") &&
                                                                      st.Destinations["all"].Count == mediaServices.Count &&
                                                                      st.Destinations["all"].First().TrackingInfo.MediaServiceName == mediaServices.First().Name)));

            var result = _updateLinkCommand.Execute(argument);

            Assert.IsTrue(result.IsActive);
            Assert.AreEqual(domainId, result.DomainId);
            Assert.AreEqual(argument.Link.MediaType, result.MediaType);
            Assert.AreEqual(argument.Link.Title, result.Title);
            Assert.AreEqual(argument.Link.Url, result.Url);
            Assert.IsNull(result.Artists);
            Assert.IsNull(result.TicketDestinations);
            Assert.IsNull(result.TrackingInfo);
            // Failed as mapping is missing
            Assert.AreEqual(2, result.MusicDestinations["all"].Count);
            Assert.AreEqual(argument.Link.MusicDestinations["all"].First().MediaServiceId, result.MusicDestinations["all"].First().MediaServiceId);
            Assert.AreEqual(argument.Link.MusicDestinations["all"].First().TrackingInfo.Web, result.MusicDestinations["all"].First().TrackingInfo.Web);
            Assert.AreEqual(argument.Link.MusicDestinations["all"].First().TrackingInfo.Mobile, result.MusicDestinations["all"].First().TrackingInfo.Mobile);
        }