public void EmptyNestGetter() { var nest = new Nest(); nest.GetNested <Egg>(); nest.Remove <Egg>(); }
public void SetNest(Nest nest) { NestEggEventType type; var lastNest = Nest; Nest = nest; if (lastNest != null && nest != null) { type = NestEggEventType.Moved; } else if (lastNest == null && nest != null) { type = NestEggEventType.Added; } else if (lastNest != null && nest == null) { type = NestEggEventType.Removed; } else { return; } InvokeKnock(new NestEggEventArgs { Self = this, Type = type, From = lastNest, To = nest, Bubble = true }); }
public void NestDoubleAddError() { var egg = new TestEgg(); var nest = new Nest(); nest.Add(egg); Assert.Throws <ContainNestException>(() => nest.Add(egg)); }
public void EggAddEvent() { var nest = new Nest(); var egg = new TestEgg(); var flag = false; egg.Knock += args => flag = args.Type == NestEggEventType.Added; nest.Add(egg); Assert.True(flag); }
public void EggBubleEvent() { var nest = new Nest(); var egg = new TestEgg(); var flag = false; nest.Knock += args => flag = args.Type == NestEggEventType.Custom && args.Self == egg; nest.Add(egg); egg.InvokeTest(); Assert.True(flag); }
public void EggMoveEvent() { var nest = new Nest(); var nest2 = new Nest(); var egg = new TestEgg(); var flag = false; egg.Knock += args => flag = args.Type == NestEggEventType.Moved && args.From == nest && args.To == nest2; nest.Add(egg); nest.MoveTo(egg, nest2); Assert.True(flag); Assert.IsNotNull(nest2.GetNested <TestEgg>()); }
public void MoveTo(Egg egg, Nest nest) { if (egg == null) { throw new NullRefNestException(string.Format("Nest {0} got empty egg", GetName())); } if (nest == null) { throw new NullRefNestException(string.Format("Nest {0} got empty nest", GetName())); } if (!_eggs.Contains(egg)) { throw new ContainNestException(string.Format("Nest {0} does not contains egg {1}", GetName(), egg.GetFullName())); } _eggs.Remove(egg); nest._eggs.Add(egg); egg.Knock -= EggOnKnock; egg.Knock += nest.EggOnKnock; egg.SetNest(nest); }
public void EmptyNestRemoveError2() { var nest = new Nest(); Assert.Throws <NullRefNestException>(() => nest.Remove(null)); }
public void EmptyNestRemoveError() { var nest = new Nest(); Assert.Throws <ContainNestException>(() => nest.Remove(new Egg())); }
public void NestNullAddError() { var nest = new Nest(); Assert.Throws <NullRefNestException>(() => nest.Add(null)); }