public void CannotCreateMusicTitleWithEmptyLengthUnit1() { Assert.Catch(() => { var x = new MusicTitle("Interpret666", "Title333", 1010, new Length(1234, ""), 999); }); }
public void CannotCreateMusicTitleWithNegativeLengthDuration() { Assert.Catch(() => { var x = new MusicTitle("Interpret666", "Title333", 1010, new Length(-1234, "s"), 999); }); }
public void CannotCreateMusicTitleWithEmptyTitle1() { Assert.Catch(() => { var x = new MusicTitle("Interpret666", null, 1010, new Length(1234, "s"), 999); }); }
public void CannotCreateMusicTitleWithEmptyInterpret1() { Assert.Catch(() => { var x = new MusicTitle(null, "Title333", 1010, new Length(1234, "s"), 999); }); }
public void CanCreateMusicTitle() { var x = new MusicTitle("Interpret666", "Title333", 1010, new Length(1234, "s"), 999); Assert.IsTrue(x.Interpret == "Interpret666"); Assert.IsTrue(x.Title == "Title333"); Assert.IsTrue(x.Year == 1010); Assert.IsTrue(x.Duration.Duration == 1234); Assert.IsTrue(x.Duration.Unit == "s"); Assert.IsTrue(x.Price == 999); }
static void Main(string[] args) { var a = new Tonaufnahme[2]; a[0] = new MusicTitle("test_Interpret", "test_Title", 2000, 179.2m, "s", 3.99m); a[1] = new Podcast("test_Publisher", "test_Title", 1999, new Length(32, "m"), 6.99m); var settings = new JsonSerializerSettings() { Formatting = Formatting.Indented, TypeNameHandling = TypeNameHandling.Auto }; string s = JsonConvert.SerializeObject(a, settings); File.WriteAllText("export.json", s); var textFromFile = File.ReadAllText("export.json"); var e = JsonConvert.DeserializeObject <Tonaufnahme[]>(textFromFile, settings); Console.WriteLine("String before Export:"); Console.WriteLine(s); Console.WriteLine("\n\nString after Import:"); Console.WriteLine(textFromFile); Console.WriteLine("\n\nCompare Titles:"); Console.Write($"a: {a[0].Title} & {a[1].Title}"); Console.WriteLine($" e: {e[0].Title} & {e[1].Title}"); Console.WriteLine("\n\nCompare Durations:"); Console.Write($"a: {Math.Round(a[0].Duration.Duration, 1)}{a[0].Duration.Unit}"); Console.WriteLine($" a: {Math.Round(a[1].Duration.Duration, 1)}{a[1].Duration.Unit}"); Console.Write($"e: {Math.Round(e[0].Duration.Duration, 1)}{e[0].Duration.Unit}"); Console.WriteLine($" e: {Math.Round(e[1].Duration.Duration, 1)}{e[1].Duration.Unit}"); Console.WriteLine("\n\n\n\n"); var b = new Podcast[4]; b[0] = new Podcast("Publisher_B1", "Title_B1", 2999, new Length(12, "s"), 10); b[1] = new Podcast("Publisher_B2", "Title_B2", 2999, new Length(12, "s"), 1); b[2] = new Podcast("Publisher_B3", "Title_B3", 2999, new Length(12, "s"), -12); b[3] = new Podcast("Publisher_B4", "Title_B4", 2999, new Length(12, "s"), 1); //Task6 var test = new Subject <Podcast>(); test .Where(x => x.Price > 0) .Subscribe(x => { Console.WriteLine($"received Podcast: {x.Title}"); }); foreach (Podcast pod in b) { test.OnNext(pod); } Console.WriteLine("\n\n\n\n"); //Task7 var random = new Random(); var sw = new Stopwatch(); sw.Start(); var tasks = new List <Task <Podcast> >(); foreach (var pod in b) { var task = Task.Run(() => { Console.WriteLine($"T1: Start {pod.Title}"); Task.Delay(TimeSpan.FromSeconds(1.0 + random.Next(2))).Wait(); Console.WriteLine($"T1: End {pod.Title}"); return(pod); }); tasks.Add(task); } sw.Stop(); Console.WriteLine(sw.Elapsed); sw.Start(); var tasks2 = new List <Task <Podcast> >(); foreach (var task in tasks) { tasks2.Add(task.ContinueWith(t => { Console.WriteLine($"T2: {t.Result.Title}"); return(t.Result); })); } Console.WriteLine(sw.Elapsed); System.Threading.Thread.Sleep(5000); Console.WriteLine(sw.Elapsed); }