Esempio n. 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);
        }