public void can_get_animals_using_explicit_relationship_between_animal_and_enclosure()
        {
            using (var sandbox = new LocalDb())
            {
                Runner.MigrateToLatest(sandbox.ConnectionString);

                using (var context = new ZooDbContext(sandbox.ConnectionString))
                {
                    var enclosure = new Enclosure()
                    {
                        Id = 1, Name = "Kenya", Location = "Africa", Environment = "Sahara"
                    };
                    var animal = new Animal()
                    {
                        Name = "Nala", Species = "Lion", EnclosureId = 1
                    };

                    context.Animals.Add(animal);
                    context.Enclosures.Add(enclosure);
                    context.SaveChanges();

                    var controller = new HomeController()
                    {
                        Database = context
                    };

                    var result = controller.Index() as ViewResult;
                    var model  = result == null ? new IndexViewModel() : result.Model as IndexViewModel;

                    Assert.Equal(1, model.Animals.Count());
                    Assert.Equal("Nala", model.Animals.First().AnimalName);
                }
            }
        }
예제 #2
0
        public Animal Create(CreateAnimalRequest newAnimal, Enclosure enclosure)
        {
            if (!_context.AnimalClasses.Any(v => v.AnimalClassification == newAnimal.AnimalClass))
            {
                AnimalClass animalClass = new AnimalClass()
                {
                    AnimalClassification = newAnimal.AnimalClass
                };

                _context.AnimalClasses.Add(animalClass);
                _context.SaveChanges();
            }
            // var enclosureId =
            //   enclosure = _context.Enclosures.GetByEnclosureName(newAnimal.EnclosureName);
            var newAnimalClass = GetAnimalClass(newAnimal.AnimalClass);
            var insertResponse = _context.Animals.Add(new Animal
            {
                AnimalName    = newAnimal.AnimalName,
                Species       = newAnimal.Species,
                Sex           = newAnimal.Sex,
                DateOfBirth   = newAnimal.DateOfBirth,
                DateAcquired  = newAnimal.DateAquired,
                AnimalClassId = newAnimalClass.AnimalClassId,
                EnclosureId   = enclosure.EnclosureId
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
        public void GetEntriesByTagIncludesEnclosure()
        {
            Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero");

            Thread.Sleep(100);
            Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one");

            UnitTestHelper.Create(entryZero);
            UnitTestHelper.Create(entryOne);


            Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3",
                                                          entryZero.Id, 12345678, true, true);

            Enclosures.Create(enc);

            var tags = new List <string>(new[] { "Tag1", "Tag2" });

            new DatabaseObjectProvider().SetEntryTagList(entryZero.Id, tags);
            new DatabaseObjectProvider().SetEntryTagList(entryOne.Id, tags);


            ICollection <Entry> entries = ObjectProvider.Instance().GetEntriesByTag(3, "Tag1");

            //Test outcome
            Assert.AreEqual(2, entries.Count, "Should have retrieved two entries.");

            Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off.");
            Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off.");

            Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure.");
            Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure.");
            UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure);
        }
        public void Can_throw_an_exception()
        {
            using (var sandbox = new LocalDb())
            {
                Runner.MigrateToLatest(sandbox.ConnectionString);

                using (var one = new ZooDbContext(sandbox.ConnectionString))
                {
                    var enclosure = new Enclosure {
                        Environment = "Here", Name = "One", Location = "Here"
                    };
                    one.Enclosures.Add(enclosure);
                    one.SaveChanges();

                    using (var two = new ZooDbContext(sandbox.ConnectionString))
                    {
                        var change = two.Enclosures.Find(enclosure.Id);
                        change.Name = "Changed";
                        two.SaveChanges();
                    }

                    enclosure.Name = "Last Time";
                    Assert.Throws <DbUpdateConcurrencyException>(() => one.SaveChanges());
                }
            }
        }
 /// <summary>
 /// Updates the specified model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="isPolling">if set to <c>true</c> [is polling].</param>
 /// <exception cref="System.Exception"></exception>
 public void Update(Enclosure model, bool isPolling)
 {
     try
     {
         HWLogger.GetFdSdkLogger(model.FusionDirectorIp).Debug($"Start UpdateEnclosure.[{model.UnionId}] [isPolling:{isPolling}]");
         var exsitEnclosure = this.GetObject($"UnionId = '{model.UnionId}'", this.EnclosureClass);
         if (exsitEnclosure == null)
         {
             throw new Exception($"Can not find the server:{model.UnionId}");
         }
         var isChange = CompareEnclosure(model, exsitEnclosure);
         if (isChange)
         {
             var discoveryData = new IncrementalDiscoveryData();
             this.UpdateEnclosure(model, exsitEnclosure);
             discoveryData.Add(exsitEnclosure);
             discoveryData.Overwrite(this.MontioringConnector);
             HWLogger.GetFdSdkLogger(model.FusionDirectorIp).Info($"Update enclosure finish.[{model.UnionId}]");
         }
     }
     catch (Exception e)
     {
         HWLogger.GetFdSdkLogger(model.FusionDirectorIp).Error(e, $"Update enclosure error.[{model.UnionId}] [isPolling:{isPolling}]");
     }
 }
        public void can_get_animals_using_explicit_relationship_between_animal_and_enclosure()
        {
            using (var sandbox = new LocalDb())
            {
                Runner.MigrateToLatest(sandbox.ConnectionString);

                using (var context = new ZooDbContext(sandbox.ConnectionString))
                {
                    var enclosure = new Enclosure() { Id = 1, Name = "Kenya", Location = "Africa", Environment = "Sahara" };
                    var animal = new Animal() { Name = "Nala", Species = "Lion", EnclosureId = 1 };

                    context.Animals.Add(animal);
                    context.Enclosures.Add(enclosure);
                    context.SaveChanges();

                    var controller = new HomeController() { Database = context };

                    var result = controller.Index() as ViewResult;
                    var model = result == null ? new IndexViewModel() : result.Model as IndexViewModel;

                    Assert.Equal(1, model.Animals.Count());
                    Assert.Equal("Nala", model.Animals.First().AnimalName);
                }
            }
        }
예제 #7
0
        public void CanUpdateEnclosure(string title, string url, string mimetype, long size, bool addToFeed,
                                       bool showWithPost)
        {
            UnitTestHelper.SetupBlog(string.Empty);
            Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Simone Chiaretta", "Post for testing Enclosures",
                                                                       "Listen to my great podcast");
            int       entryId = UnitTestHelper.Create(e);
            Enclosure enc     = UnitTestHelper.BuildEnclosure(title, url, mimetype, entryId, size, addToFeed, showWithPost);

            Enclosures.Create(enc);

            string randomStr = UnitTestHelper.GenerateUniqueString().Left(20);

            enc.Url = url + randomStr;

            if (!string.IsNullOrEmpty(title))
            {
                enc.Title = title + randomStr;
            }

            enc.MimeType = mimetype + randomStr;

            int randomSize = new Random().Next(10, 100);

            enc.Size = size + randomSize;

            Assert.IsTrue(Enclosures.Update(enc), "Should have updated the Enclosure");

            Entry newEntry = ObjectProvider.Instance().GetEntry(entryId, true, false);

            UnitTestHelper.AssertEnclosures(enc, newEntry.Enclosure);
        }
예제 #8
0
 public void Clean()
 {
     if (Enclosure.StartsWith("//"))
     {
         Enclosure += "http:";
     }
 }
        public void RssWriterProducesValidFeedWithEnclosureFromDatabase()
        {
            string hostName = UnitTestHelper.GenerateUniqueString() + ".com";

            Config.CreateBlog("Test", "username", "password", hostName, string.Empty);

            UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "");
            BlogRequest.Current.Blog = Config.GetBlog(hostName, string.Empty);
            Config.CurrentBlog.Email = "*****@*****.**";
            Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false;

            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null,
                                                                           NullValue.NullDateTime);

            entry.DateCreated    = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.DateSyndicated = entry.DateCreated;
            int entryId = UnitTestHelper.Create(entry); //persist to db.

            string enclosureUrl      = "http://perseus.franklins.net/hanselminutes_0107.mp3";
            string enclosureMimeType = "audio/mp3";
            long   enclosureSize     = 26707573;

            Enclosure enc =
                UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>",
                                              enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true);

            Enclosures.Create(enc);

            var    subtextContext = new Mock <ISubtextContext>();
            string rssOutput      = null;

            subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            Mock <UrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);

            urlHelper.Setup(u => u.BlogUrl()).Returns("/");
            urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/archive/2008/01/23/testtitle.aspx");

            XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput);

            Assert.AreEqual(1, itemNodes.Count, "expected one item nodes.");

            string urlFormat   = "http://{0}/archive/2008/01/23/{1}.aspx";
            string expectedUrl = string.Format(urlFormat, hostName, "testtitle");

            Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("title").InnerText,
                            "Not what we expected for the title.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("link").InnerText,
                            "Not what we expected for the link.");
            Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("guid").InnerText,
                            "Not what we expected for the guid.");
            Assert.AreEqual(enclosureUrl, itemNodes[0].SelectSingleNode("enclosure/@url").InnerText,
                            "Not what we expected for the enclosure url.");
            Assert.AreEqual(enclosureMimeType, itemNodes[0].SelectSingleNode("enclosure/@type").InnerText,
                            "Not what we expected for the enclosure mimetype.");
            Assert.AreEqual(enclosureSize.ToString(), itemNodes[0].SelectSingleNode("enclosure/@length").InnerText,
                            "Not what we expected for the enclosure size.");
            Assert.AreEqual(expectedUrl + "#feedback", itemNodes[0].SelectSingleNode("comments").InnerText,
                            "Not what we expected for the link.");
        }
예제 #10
0
        public RSSItem(XmlNode xmlNode)
        {
            this.xmlNode   = xmlNode;
            Title          = RSSSimpleElement("title");
            Link           = RSSSimpleElement("link");
            Description    = RSSSimpleElement("description");
            Author         = RSSSimpleElement("author");
            Comments       = RSSSimpleElement("comments");
            PubDate        = RSSFormatDate("pubDate");
            PubDateNoSpace = RSSFormatDate("pubDate", true);
            Category category = new Category(
                RSSSimpleElement("category"),
                RSSSimpleElement("category/@domain")
                );

            enclosure = new Enclosure(
                RSSSimpleElement("enclosure/@url"),
                RSSSimpleElement("enclosure/@length"),
                RSSSimpleElement("enclosure/@type")
                );
            guid = new GUID(
                RSSSimpleElement("guid"),
                RSSSimpleElement("guid/@isPermaLink")
                );
            source = new Source(
                RSSSimpleElement("source"),
                RSSSimpleElement("source/@url")
                );
        }
예제 #11
0
        public Enclosure UpdateEnclosure(Enclosure enclosure)
        {
            try
            {
                using (var db = this.GetContext())
                {
                    if (ValidateSessionId(db))
                    {
                        return(db.UpdateEnclosure(enclosure));
                    }
                    else
                    {
                        throw new AuthenticationException("Couldn't validate the session");
                    }
                }
            }
            catch (Exception Exp)
            {
                string EnclosureInput = "Id: " + enclosure.id + ", name: " + enclosure.name +
                                        ", Icon Url: " + enclosure.markerIconUrl + ", Marker X: " + enclosure.markerX +
                                        ", Marker Y: " + enclosure.markerY + ", marker closest point x: " + enclosure.markerClosestPointX +
                                        ", marker closest point y: " + enclosure.markerClosestPointY +
                                        "Picture Url: " + enclosure.pictureUrl;

                Logger.GetInstance(isTesting).WriteLine(Exp.Message, Exp.StackTrace, "Enclosure: " + EnclosureInput);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
예제 #12
0
        static void enclosureEnd(Enclosure ended)
        {
            switch (ended.type)
            {
            case NT.IF: break;

            case NT.MEMBER_TUPLE: {
                AST_Tuple      tuple = (AST_Tuple)ended.node;
                DataType_Tuple tupleType;
                ValueKind      tupleKind;
                getTuple_Type_Kind(tuple, out tupleType, out tupleKind);
                tuple.result = new IR {
                    irType = NT.TUPLE, dType = tupleType, dKind = tupleKind
                };

                // TODO: only allow members
            } break;

            case NT.FUNCTION: if (!isDefineFase)
                {
                    swap(ref instructions, ref ((IR_Function)ended.node.result).block);
                }
                break;

            case NT.STRUCT: {
                var structNode = (AST_Struct)ended.node;
                var structType = (DataType_Struct)structNode.result.dType;

                DataType[] members;
                if (structNode.inherits != null)
                {
                    members    = new DataType[structType.members.Length + 1];
                    members[0] = structNode.inherits.result.dType;
                    structType.members.CopyTo(members, 1);
                }
                else
                {
                    members = new DataType[structType.members.Length];
                    structType.members.CopyTo(members, 0);
                }
                structNode.result = instructions.Add(new IR {
                        irType = NT.STRUCT, dType = structType, dKind = ValueKind.STATIC_TYPE
                    });

                if (structNode.inherits != null)
                {
                    if (structNode.inherits.result.dKind != ValueKind.STATIC_TYPE || !(structNode.inherits.result.dType is DataType_Struct))
                    {
                        throw Jolly.addError(structNode.inherits.location, "Can only inherit from other structs");
                    }
                    structType.inherits = (DataType_Struct)structNode.inherits.result.dType;
                }
            } break;

            case NT.OBJECT: break;

            default: throw Jolly.addError(ended.node.location, "Internal compiler error: illigal node used as enclosure");
            }     // switch(ended.type)
        }
        public void GetPostsByCategoryIDReturnsDaysWithEnclosure()
        {
            //Create Category
            int blogId     = Config.CurrentBlog.Id;
            int categoryId = UnitTestHelper.CreateCategory(blogId, "Test Category");

            //Create some entries.
            Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero");

            Thread.Sleep(100);
            Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one");

            Thread.Sleep(100);
            Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");

            Thread.Sleep(100);
            Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");

            entryThree.DateCreated = DateTime.Now.AddDays(1);

            //Associate Category
            entryZero.Categories.Add("Test Category");
            entryOne.Categories.Add("Test Category");
            entryThree.Categories.Add("Test Category");


            //Persist entries.
            UnitTestHelper.Create(entryZero);
            UnitTestHelper.Create(entryOne);
            UnitTestHelper.Create(entryTwo);
            UnitTestHelper.Create(entryThree);

            //Add Enclosure
            Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3",
                                                          entryZero.Id, 12345678, true, true);

            Enclosures.Create(enc);

            //Get EntryDay
            ICollection <EntryDay> entryList = ObjectProvider.Instance().GetBlogPostsByCategoryGroupedByDay(10, categoryId).ToList();

            var days = new EntryDay[2];

            entryList.CopyTo(days, 0);

            //Test outcome
            Assert.AreEqual(2, entryList.Count, "Expected to find two days.");

            EntryDay entries = days[1];

            Assert.AreEqual(2, entries.Count, "Expected to find two entries.");

            Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off.");
            Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off.");

            Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure.");
            Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure.");
            UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure);
        }
        public void EnclosureNonExistantMixins_ReturnsNull()
        {
            Enclosure enclosure = new Enclosure();

            Assert.AreEqual(null, enclosure.ImprovementCost(enclosure._qualityCounter));
            Assert.AreEqual(null, enclosure.MaintenanceCost(enclosure._quality, enclosure._sustain));
            Assert.AreEqual(null, enclosure.MigrationCost(enclosure._quality));
        }
예제 #15
0
 public static FileUrl Build(Enclosure enclosure)
 {
     return(new FileUrl
     {
         Url = enclosure.Url,
         OriginalFileName = Path.GetFileName(enclosure.Url),
         FriendlyFileName = enclosure.Lesson.Title.ToFileName() + Path.GetExtension(enclosure.Url),
     });
 }
예제 #16
0
 /// <summary>
 /// Constructor used by the serialization infrastructure.
 /// </summary>
 /// <param name="info">The serialization information.</param>
 /// <param name="context">The serialization context.</param>
 private DownloadItem(SerializationInfo info, StreamingContext context)
 {
     downloadItemId = (Guid)info.GetValue("_id", typeof(Guid));
     ownerItemId    = info.GetString("_itemId");
     ownerFeedId    = info.GetString("_ownerId");
     enclosure      = new Enclosure(info.GetString("_mimetype"), info.GetInt64("_length"), info.GetString("_url"),
                                    info.GetString("_description"));
     file = new DownloadFile(enclosure);
 }
예제 #17
0
 public static void AssertEnclosures(Enclosure expected, Enclosure result)
 {
     Assert.AreEqual(expected.Title, result.Title, "Wrong title.");
     Assert.AreEqual(expected.Url, result.Url, "Wrong Url.");
     Assert.AreEqual(expected.MimeType, result.MimeType, "Wrong mimetype.");
     Assert.AreEqual(expected.Size, result.Size, "Wrong size.");
     Assert.AreEqual(expected.AddToFeed, result.AddToFeed, "Wrong AddToFeed flag.");
     Assert.AreEqual(expected.ShowWithPost, result.ShowWithPost, "Wrong ShowWithPost flag.");
 }
        public void SizeIsFormattedCorrectly(long size, string expected)
        {
            var enc = new Enclosure {
                Size = size
            };

            Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");
            Assert.AreEqual(expected, enc.FormattedSize, "Not the right formatting");
        }
예제 #19
0
 /// <summary>
 /// Creates a DownloadItem using the owner ID of the creating instance.
 /// </summary>
 /// <param name="ownerFeedId">The download owner ID.</param>
 /// <param name="ownerItemId">The download item ID</param>
 /// <param name="enclosure">Information about the item to download</param>
 /// <param name="downloadInfo">Information needed to download the files that is independent of the file</param>
 public DownloadItem(string ownerFeedId, string ownerItemId, Enclosure enclosure,
                     IDownloadInfoProvider downloadInfo)
 {
     this.ownerFeedId  = ownerFeedId;
     this.ownerItemId  = ownerItemId;
     this.enclosure    = enclosure;
     file              = new DownloadFile(enclosure);
     this.downloadInfo = downloadInfo;
 }
예제 #20
0
        public void GetRecentPostsIncludesEnclosure()
        {
            int blogId = Config.CurrentBlog.Id;

            for (int i = 0; i < 10; i++)
            {
                UnitTestHelper.CreateCategory(blogId, "cat" + i);
            }

            //Create some entries.
            Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero");

            Thread.Sleep(100);
            Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one");

            Thread.Sleep(100);
            Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");

            //Associate categories.
            for (int i = 0; i < 5; i++)
            {
                entryZero.Categories.Add("cat" + (i + 1));
                entryOne.Categories.Add("cat" + i);
            }
            entryTwo.Categories.Add("cat8");

            //Persist entries.
            UnitTestHelper.Create(entryZero);
            UnitTestHelper.Create(entryOne);
            UnitTestHelper.Create(entryTwo);
            var repository = new DatabaseObjectProvider();

            Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3",
                                                          entryZero.Id, 12345678, true, true);

            repository.Create(enc);

            //Get Entries
            ICollection <Entry> entries = repository.GetEntries(3, PostType.BlogPost, PostConfig.IsActive, true);

            //Test outcome
            Assert.AreEqual(3, entries.Count, "Expected to find three entries.");

            Assert.AreEqual(entries.First().Id, entryTwo.Id, "Ordering is off.");
            Assert.AreEqual(entries.ElementAt(1).Id, entryOne.Id, "Ordering is off.");
            Assert.AreEqual(entries.ElementAt(2).Id, entryZero.Id, "Ordering is off.");

            Assert.AreEqual(1, entries.First().Categories.Count);
            Assert.AreEqual(5, entries.ElementAt(1).Categories.Count);
            Assert.AreEqual(5, entries.ElementAt(2).Categories.Count);

            Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure.");
            Assert.IsNull(entries.ElementAt(1).Enclosure, "Entry should not have enclosure.");
            Assert.IsNotNull(entries.ElementAt(2).Enclosure, "Entry should have enclosure.");
            UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(2).Enclosure);
        }
예제 #21
0
        /// <summary>
        /// Ajoute une PJ au formulaire et à l'action correspondante
        /// </summary>
        /// <param name="pj">PJ à inclure</param>
        public void addPJToForm(Enclosure pj)
        {
            // Ajout du lien à l'action
            int index = _action.addPJ(pj);

            // Ajout à la linksView
            this.addPJToView(pj, index);
            // Affichage de la linksView
            this.linksView.Visible = true;
        }
        public void Entertain_Succeeds()
        {
            Enclosure enclosure = new Enclosure()
            {
                _quality = 3
            };

            Assert.AreEqual(4, enclosure.Enclose(DateTime.Now.AddHours(-2), DateTime.Now));
            Assert.AreEqual(-2, enclosure._qualityCounter);
        }
 public override int Create(Enclosure enclosure)
 {
     return(_procedures.InsertEnclosure(enclosure.Title ?? string.Empty,
                                        enclosure.Url,
                                        enclosure.MimeType,
                                        enclosure.Size,
                                        enclosure.AddToFeed,
                                        enclosure.ShowWithPost,
                                        enclosure.EntryId));
 }
예제 #24
0
        public void GetHomePageEntriesReturnsDaysWithEnclosure()
        {
            //Create some entries.
            Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero");

            entryZero.DatePublishedUtc = DateTime.UtcNow.AddDays(-1);
            entryZero.IsActive         = entryZero.IncludeInMainSyndication = true;
            Thread.Sleep(100);
            Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one");

            entryOne.DatePublishedUtc = DateTime.UtcNow.AddDays(-1);
            entryOne.IsActive         = entryOne.IncludeInMainSyndication = true;
            Thread.Sleep(100);
            Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");

            entryTwo.DisplayOnHomePage = false;
            Thread.Sleep(100);
            Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");

            entryThree.IsActive = entryThree.IncludeInMainSyndication = true;

            //Persist entries.
            UnitTestHelper.Create(entryZero);
            UnitTestHelper.Create(entryOne);
            UnitTestHelper.Create(entryTwo);
            UnitTestHelper.Create(entryThree);
            var repository = new DatabaseObjectProvider();

            //Add Enclosure
            Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3",
                                                          entryZero.Id, 12345678, true, true);

            repository.Create(enc);

            //Get EntryDay
            ICollection <EntryDay> entryList = repository.GetBlogPostsForHomePage(10, PostConfig.DisplayOnHomepage | PostConfig.IsActive).ToList();

            var days = new EntryDay[2];

            entryList.CopyTo(days, 0);

            //Test outcome
            Assert.AreEqual(2, entryList.Count, "Expected to find two days.");

            EntryDay entries = days[1];

            Assert.AreEqual(2, entries.Count, "Expected to find two entries.");

            Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off.");
            Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off.");

            Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure.");
            Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure.");
            UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure);
        }
예제 #25
0
        public Enclosure Build(int enclosureId, char enclosureName)
        {
            var enclosure = new Enclosure(enclosureId, enclosureName);

            foreach (var animalInfo in animals)
            {
                var animal = AnimalFactory.CreateAnimal(animalInfo.Item1, animalInfo.Item2);
                enclosure.AddAnimal(animal);
            }
            return(enclosure);
        }
        public void EnclosureMaintenanceCost_Succeeds()
        {
            Enclosure enclosure = new Enclosure(null, new MaintenancePolitics())
            {
                _qualityCounter = -45, _sustain = 10.50
            };

            Assert.AreEqual(null, enclosure.ImprovementCost(enclosure._qualityCounter));
            Assert.AreEqual(10.5, enclosure.MaintenanceCost(enclosure._quality, enclosure._sustain));
            Assert.AreEqual(null, enclosure.MigrationCost(enclosure._quality));
        }
        private bool CompareEnclosure(Enclosure model, MonitoringObject existObj)
        {
            var propertys = this.EnclosureClass.PropertyCollection;

            if (existObj[propertys["Name"]].Value.ToString() != model.Name)
            {
                return(true);
            }
            if (existObj[propertys["Type"]].Value.ToString() != model.Type.ToString())
            {
                return(true);
            }
            if (existObj[propertys["FirmwareVersion"]].Value.ToString() != model.FirmwareVersion.ToString())
            {
                return(true);
            }
            if (existObj[propertys["Hostname"]].Value.ToString() != model.Hostname.ToString())
            {
                return(true);
            }
            if (existObj[propertys["SerialNumber"]].Value.ToString() != model.SerialNumber.ToString())
            {
                return(true);
            }
            if (existObj[propertys["PartNumber"]].Value.ToString() != model.PartNumber.ToString())
            {
                return(true);
            }
            if (existObj[propertys["ProductName"]].Value.ToString() != model.ProductName.ToString())
            {
                return(true);
            }
            if (existObj[propertys["EnclosureState"]].Value.ToString() != model.EnclosureState.ToString())
            {
                return(true);
            }
            if (existObj[propertys["StateReason"]].Value.ToString() != model.StateReason.ToString())
            {
                return(true);
            }
            if (existObj[propertys["FanSpeedAdjustmentMode"]].Value.ToString() != model.FanSpeedAdjustmentMode.ToString())
            {
                return(true);
            }
            if (existObj[propertys["HMMFloatIPv4Address"]].Value.ToString() != model.HMMFloatIPv4Address.ToString())
            {
                return(true);
            }
            if (existObj[propertys["Health"]].Value.ToString() != model.Health.ToString())
            {
                return(true);
            }
            return(false);
        }
 public override bool Update(Enclosure enclosure)
 {
     return(_procedures.UpdateEnclosure(enclosure.Title,
                                        enclosure.Url,
                                        enclosure.MimeType,
                                        enclosure.Size,
                                        enclosure.AddToFeed,
                                        enclosure.ShowWithPost,
                                        enclosure.EntryId,
                                        enclosure.Id));
 }
예제 #29
0
        //[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
        public IActionResult TestDownLoadEnclosure(long Id)
        {
            var       webRootPath = _hostingEnvironment.WebRootPath;
            Enclosure picture     = new Enclosure();

            picture = _enclosureService.TestDownLoadEnclosure(Id);
            var        addrUrl = Path.Combine(Directory.GetCurrentDirectory(), $@"{webRootPath + picture.FilePath}");
            FileStream fs      = new FileStream(addrUrl, FileMode.Open);

            return(File(fs, "application/vnd.android.package-archive", picture.FilePath));
        }
        public void Create_WithInvalidEntry_ThrowsArgumentException()
        {
            // arrange
            var enclosure = new Enclosure {
                EntryId = 0
            };

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            UnitTestHelper.AssertThrows <ArgumentException>(() => Enclosures.Create(enclosure));
        }
예제 #31
0
        public void Create_WithInvalidEntry_ThrowsArgumentException()
        {
            // arrange
            var repository = new DatabaseObjectProvider();
            var enclosure  = new Enclosure {
                EntryId = 0
            };

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            UnitTestHelper.AssertThrows <ArgumentException>(() => repository.Create(enclosure));
        }
        public void Can_throw_an_exception()
        {
            using (var sandbox = new LocalDb())
            {
                Runner.MigrateToLatest(sandbox.ConnectionString);

                using (var one = new ZooDbContext(sandbox.ConnectionString))
                {
                    var enclosure = new Enclosure {Environment = "Here", Name = "One", Location = "Here"};
                    one.Enclosures.Add(enclosure);
                    one.SaveChanges();

                    using (var two = new ZooDbContext(sandbox.ConnectionString))
                    {
                        var change = two.Enclosures.Find(enclosure.Id);
                        change.Name = "Changed";
                        two.SaveChanges();
                    }

                    enclosure.Name = "Last Time";
                    Assert.Throws<DbUpdateConcurrencyException>(() =>  one.SaveChanges());
                }
            }
        }