public void TestSaveMediaValidEntity() { // Arrange var options = BuildTestDbOptions(); var testEntity = new Media { FileName = "test file" }; // Act using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); var repository = new MediaRepository(context); repository.AddMedia(testEntity); } // Assert using (var context = new ApplicationDbContext(options)) { var result = context.Media.ToList(); Assert.Contains(result, m => m.FileName == "test file"); Assert.Equal(16, result.Count); context.Database.EnsureDeleted(); } }
public void TestSaveMediaNullEntity() { // Arrange var options = BuildTestDbOptions(); Media testEntity = null; // Act using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); var repository = new MediaRepository(context); repository.AddMedia(testEntity); } // Assert using (var context = new ApplicationDbContext(options)) { var result = context.Media.ToList(); Assert.Equal(15, result.Count); context.Database.EnsureDeleted(); } }
public ViewResult Media() { if (MediaRepository.Medias.Count == 0) { Media m1 = new Media { mediaTitle = "Fall of Reach", summary = "The novel opens with the civilian Dr. Catherine Halsey and Lieutenant Jacob Keyes traveling to meet John, a six-year-old boy. Dr. Halsey reveals to Keyes that John is one of 150 children who possess rare genetic markers making them suitable for conscription into the SPARTAN-II program, a secret experiment with the aim of creating super soldiers for the UNSC to quell rebellions.[9] Seventy-five of the children are kidnapped by operatives of the Office of Naval Intelligence and replaced by clones engineered to die of natural causes shortly thereafter. From this point on, the recruits are known only by their first name and a three digit number. John-117 and the rest of the children are drilled and trained by Franklin Mendez; John demonstrates leadership of his fellow Spartans leading to his promotion to squad leader. In 2525, the Spartans undergo a series of surgical enhancements which turn them into highly efficient super soldiers - but more than half of the original 75 conscripts are paralyzed or killed.[10] The Spartans are also equipped with powerful MJOLNIR battle armor, designed to respond as quickly as the soldier's thoughts. John-117 is further promoted to Master Chief Petty Officer.[11] The Spartans are highly successful, but they experience a priority shift after a collective of alien races known as the Covenant begin obliterating human colonies, declaring humanity's destruction as the will of their gods. Mendez leaves the group to train the next generation of Spartans as John and his comrades first face the Covenant. By 2552, the war against the Covenant is going poorly. The technological superiority of the Covenant means that space battles heavily favor the Covenant, and the UNSC can only win engagements by suffering tremendous losses.To prevent the discovery of Earth or other human colonies, Vice Admiral Cole creates the Cole Protocol, which forbids direct slipspace jumps to Earth or any other population center and mandates the destruction of a ship before it can be captured by the Covenant.Jacob Keyes, now commander of the destroyer Iroquois, discovers four Covenant ships arriving at the Sigma Octanus System, and single - handedly destroys three of them; his heroics earn Keyes the rank of Captain. The Covenant proceed to overrun Sigma Octanus IV, searching for a mysterious ancient artifact.Despite a costly fight, the humans manage to repel the Covenant, and Keyes intercepts a coded Covenant transmission from the surface before the Covenant retreat.[13] The Iroquois heads to Reach, unwittingly bringing a Covenant tracking device with it. Soon after, Keyes is given the command of the UNSC cruiser Pillar of Autumn for a secret mission; the Spartans are to capture one of the Covenant's religious leaders and barter a truce.[15] Dr. Halsey also introduces John to the artificial intelligence Cortana, who would assist the Spartans by residing in their MJOLNIR armor.[16] Before the mission can begin, however, Reach is attacked by a massive Covenant fleet. John and Cortana reach the Pillar of Autumn, but most of the other Spartans are presumed killed as the Covenant vitrify the surface of Reach, turning the landmasses into glass.[17] Cortana initiates a slipspace course based on the ancient glyphs intercepted by the Covenant at Sigma Octanus, the course takes them to a massive ringworld known as Halo, setting the stage for the events of Halo: Combat Evolved.", link = "https://en.wikipedia.org/wiki/Halo:_The_Fall_of_Reach" }; Media m2 = new Media { mediaTitle = "The Flood", summary = "The novel, like the video game it is based on, begins as the Pillar of Autumn exits slipspace, discovering an unexpected massive ringworld hidden by a moon in orbit around a gas giant. In the system are a host of Covenant, who notice the lone ship. A Covenant leader forbids the fleet to fire on the Autumn, for fear of damaging the ring. Instead, they board and capture the ship. Meanwhile, technicians on the Autumn prepare for battle and awaken a single soldier from cryo sleep—a Spartan known as the Master Chief. The Covenant board the Autumn; deprived of defensive options, the Autumn's captain, Jacob Keyes, tells the crew to abandon ship. The Master Chief is entrusted with the artificial intelligence Cortana; given the wealth of tactical information the A.I. contains, Keyes cannot allow Cortana to fall into enemy hands. The Master Chief leaves for the surface of Halo in a lifeboat; other soldiers, including a squad of shock troops led by Antonio Silva and his second-in-command, Melissa McKay, land by special drop pods, and take a strategic bluff from the Covenant to use as a base of operations. Captain Keyes is captured by the Covenant, and taken aboard the Covenant cruiser Truth and Reconciliation; the Master Chief and a squad of Marines board the Truth and Reconciliation, rescuing the captain. Keyes has learned that the ringworld they are on has vast significance to the Covenant- they believe that Halo, as they call the ring, is a weapon of unimaginable power. Escaping from the Covenant cruiser, Keyes gives the Master Chief the mission of finding the Control Room of Halo before the Covenant. The Master Chief and Cortana discover the location of the Control Room, and with the help of some Marines, insert Cortana into Halo's computer network.However, Cortana realizes that the ring is not a weapon as they understood at all - but before the Chief can press her with questions, Cortana tells the Master Chief to find Captain Keyes. Dropped into the swamp where Keyes and his squad disappeared, the Master Chief discovers that the Captain has been captured and both human and Covenant soldiers have been turned into zombie-like creatures by bulbous aliens. One soldier, Private Wallace Jenkins, is left still semi - conscious and painfully aware of his predicament, unable to control his movement or actions as his former friends and he attack McKay's troops. Jenkins intends on ending his life, but is instead captured by McKay for study. The Chief is approached by Halo's resident A.I., 343 Guilty Spark, who informs the Chief that the creatures he has encountered are called the Flood, a virulent parasite that infects hosts and converts them into either forms for combat, or for reproduction.To activate Halo's defenses, Guilty Spark needs the Master Chief's help.In Halo's Control Room, Guilty Spark gives the Master Chief the key to activate Halo, but is stopped by a furious Cortana. Cortana explains that Halo is a weapon, but it doesn't kill the Flood - it kills their food, meaning humans, Covenant, and any other sentient life.Realizing that they have to stop Guilty Spark from activating Halo, Cortana and the Master Chief decide to destroy Halo by detonating the crash - landed Pillar of Autumn's fusion reactors. In order to do this, they need Captain Keyes' neural implants.Cortana discovers the Captain is still alive, held prisoner once again aboard the Truth and Reconciliation, now in the hands of the Flood who are trying to escape Halo.The Chief fights Covenant and Flood to the Captain, but finds out he is too late—the Captain has been assimilated into the parasite.The Chief retrieves the implants and leaves the Truth for the Autumn. While the Chief and Cortana head to the Autumn, Alpha Base is evacuated.Silva decides to retake the Truth and Reconciliation and pilot the ship away in order to avoid being on Halo when the Autumn blows.The ship is taken successfully, but McKay realizes that Silva is blinded by the thought of promotion and glory to the danger of the Flood; if even one Flood specimen escaped containment on Earth, the entire planet could fall.Jenkins draws McKay's attention to a vital energy line on the ship, and realizing that the destruction of the Flood is more important than Silva's promotion, cuts the cable, sending the Truth and Reconciliation crashing into Halo, killing all aboard.", link = "https://en.wikipedia.org/wiki/Halo:_The_Flood" }; Media m3 = new Media { mediaTitle = "First Strike", summary = "The novel begins in orbit above planet Reach, as humanity fights the Covenant invasion forces. The last line of defense for the planet is an array of magnetic accelerator cannons (MACs) orbiting the planet. The Master Chief sends a team of Spartans to the surface of Reach to protect the MAC's planet-based power generators.[5][6] Ultimately, the Covenant are able to destroy the generators and begin bombarding the planet's surface - melting its surface to glass ('glassing the planet'). The surviving Spartans flee underground to the hidden headquarters of the Office of Naval Intelligence.[7] There they meet Dr. Halsey who, with help of some of the surviving Spartans, uncovers a strange crystalline shard in a cavern built by the ancient Forerunners. Pursued by the Covenant, the Spartans retrieve the shard and collapse the passage behind them, which saves them from the pursuing Covenant forces, but also traps them deep under the surface of Reach. The book then shifts to events occurring soon after Halo, as the Master Chief and Cortana drift through the ruins of Halo, they discover other survivors including Sergeant Johnson and Corporal Locklear. The group commandeer the Covenant flagship Ascendant Justice and use its slipspace capabilities to return to the Reach system.To prevent the Covenant finding Earth with a tracking device, the humans plan to find a suitably undamaged human ship to take them to Earth.[10] Upon arrival the group receive a radio signal used by the Spartans in their training days.[11] On the surface, they find three Spartans and Vice Admiral Danforth Whitcomb, the Deputy Chief of Naval Operations.The Vice Admiral arms a Nova thermonuclear mine, a weapon that would destroy the planet. The Master Chief and his newly acquired team of Spartans then proceed to rescue Dr.Halsey and the other Spartans that were trapped under the surface of the planet.[13] Meanwhile, Cortana, still aboard Ascendant Justice, learns that the Covenant already know the location of Earth and are preparing an invasion fleet. Seeking the Forerunner shard, the Covenant attack, severely damaging Ascendant Justice, but are temporarily defeated. In order to make repairs, the UNSC forge an alliance with human separatists hidden in an asteroid field.Halsey abducts Spartan Kelly-087 and flees in a stolen ship, leaving Corporal Locklear with instructions to stop the crystal from falling into Covenant hands. Locklear decides to destroy the crystal, inadvertently killing himself, but stopping the Covenant from tracking the crystal's radioactive emissions and by extension the Ascendant Justice. With the knowledge that the Covenant are en route to Earth, the Master Chief and his fellow Spartans decide to disrupt the invasion force at their rendezvous point.The Spartans successfully infiltrate the Covenant space station, Unyielding Hierophant, set it to self-destruct and escape in a drop-ship.[15] On board the Ascendant Justice, Whitcomb tricks the Covenant fleet into following the ship closer to the Unyielding Hierophant; when the station explodes the entire Covenant armada is destroyed or damaged.[16] Master Chief and the surviving Spartans take the salvaged UNSC ship, Gettysburg, back to Earth with Sgt.Johnson and Cortana to warn of the approaching invasion.[17] Meanwhile, the Covenant leadership discuss the fate of the incompetent one, an Elite who allowed Halo to be destroyed and Ascendant Justice to be captured; setting the stage for Halo 2.", link = "https://en.wikipedia.org/wiki/Halo:_First_Strike" }; MediaRepository.AddMedia(m1); MediaRepository.AddMedia(m2); MediaRepository.AddMedia(m3); } ViewBag.m = MediaRepository.Medias; return(View("Media", MediaRepository.Medias)); }
/// <summary> /// Merges source to target, source takes precedence /// </summary> /// <param name="source">The source</param> /// <param name="target">The target</param> /// <param name="honorSourceOrder">Whether to honor the order in source</param> public static void Merge(MediaRepository source, MediaRepository target, bool honorSourceOrder = false) { if (source.Version != null) { target.Version = source.Version; } foreach (var srcmi in source.MediaList) { var id = srcmi.Id; if (id == null) { continue; } if (!target.IdToInfo.TryGetValue(id, out var tgtmi)) { tgtmi = new MediaInfo { Id = id }; target.AddMedia(tgtmi); } if (srcmi.Title != null) { tgtmi.Title = srcmi.Title; } if (srcmi.DateStr != null) { tgtmi.DateStr = srcmi.DateStr; } if (srcmi.Category != null) { tgtmi.Category = srcmi.Category; } if (srcmi.Role != null) { tgtmi.Role = srcmi.Role; } if (srcmi.Director != null) { tgtmi.Director = srcmi.Director; } if (srcmi.Playwright != null) { tgtmi.Playwright = srcmi.Playwright; } if (srcmi.AdaptedFrom != null) { tgtmi.AdaptedFrom = srcmi.AdaptedFrom; } if (srcmi.ExternalLink != null) { tgtmi.ExternalLink = srcmi.ExternalLink; } } if (honorSourceOrder) { var srcIdToIndex = new Dictionary <string, int>(); for (var i = 0; i < source.MediaList.Count; i++) { var srcmi = source.MediaList[i]; srcIdToIndex[srcmi.Id] = i; } var oldTgtIdToIndex = new Dictionary <string, int>(); for (var i = 0; i < target.MediaList.Count; i++) { var tgtmi = target.MediaList[i]; oldTgtIdToIndex[tgtmi.Id] = i; } target.MediaList.Sort((a, b) => { if (srcIdToIndex.TryGetValue(a.Id, out var srcia) && srcIdToIndex.TryGetValue(b.Id, out var srcib)) { return(srcia.CompareTo(srcib)); } if (oldTgtIdToIndex.TryGetValue(a.Id, out var tgtia) && oldTgtIdToIndex.TryGetValue(b.Id, out var tgtib)) { return(tgtia.CompareTo(tgtib)); } if (a.DateStr != null && b.DateStr != null) { var c = a.DateStr.CompareTo(b.DateStr); if (c != 0) { return(c); } } if (a.Title != null && b.Title != null) { var c = a.Title.CompareTo(b.Title); if (c != 0) { return(c); } } return(a.Id.CompareTo(b.Id)); }); } }