Best Nunit code snippet using B.Dummy1
BindTests.cs
Source:BindTests.cs
...10 {11 [Test]12 public void BindToSingle()13 {14 Container.Binder.Bind<IDummy>().To<Dummy1>().AsSingleton();15 var instance1 = Container.Resolver.Resolve<IDummy>();16 var instance2 = Container.Resolver.Resolve<IDummy>();17 Assert.IsNotNull(instance1);18 Assert.IsNotNull(instance2);19 Assert.That(instance1, Is.EqualTo(instance2));20 Assert.That(instance1, Is.TypeOf<Dummy1>());21 Assert.That(instance2, Is.TypeOf<Dummy1>());22 }23 [Test]24 public void BindToTransient()25 {26 Container.Binder.Bind<IDummy>().To<Dummy1>().AsTransient();27 var instance1 = Container.Resolver.Resolve<IDummy>();28 var instance2 = Container.Resolver.Resolve<IDummy>();29 Assert.IsNotNull(instance1);30 Assert.IsNotNull(instance2);31 Assert.That(instance1, !Is.EqualTo(instance2));32 Assert.That(instance1, Is.TypeOf<Dummy1>());33 Assert.That(instance2, Is.TypeOf<Dummy1>());34 }35 [Test]36 public void BindToInstance()37 {38 Container.Binder.Bind<IDummy>().ToInstance(new Dummy1());39 var instance1 = Container.Resolver.Resolve<IDummy>();40 var instance2 = Container.Resolver.Resolve<IDummy>();41 Assert.IsNotNull(instance1);42 Assert.IsNotNull(instance2);43 Assert.That(instance1, Is.EqualTo(instance2));44 Assert.That(instance1, Is.TypeOf<Dummy1>());45 Assert.That(instance2, Is.TypeOf<Dummy1>());46 }47 [Test]48 public void BindToSingleMethod()49 {50 Container.Binder.Bind<IDummy>().ToMethod(c => new Dummy1()).AsSingleton();51 var instance1 = Container.Resolver.Resolve<IDummy>();52 var instance2 = Container.Resolver.Resolve<IDummy>();53 Assert.IsNotNull(instance1);54 Assert.IsNotNull(instance2);55 Assert.That(instance1, Is.EqualTo(instance2));56 Assert.That(instance1, Is.TypeOf<Dummy1>());57 Assert.That(instance2, Is.TypeOf<Dummy1>());58 }59 [Test]60 public void BindToTransientMethod()61 {62 Container.Binder.Bind<IDummy>().ToMethod(c => new Dummy1()).AsTransient();63 var instance1 = Container.Resolver.Resolve<IDummy>();64 var instance2 = Container.Resolver.Resolve<IDummy>();65 Assert.IsNotNull(instance1);66 Assert.IsNotNull(instance2);67 Assert.That(instance1, !Is.EqualTo(instance2));68 Assert.That(instance1, Is.TypeOf<Dummy1>());69 Assert.That(instance2, Is.TypeOf<Dummy1>());70 }71 [Test]72 public void BindToFactory()73 {74 var factory = Substitute.For<IInjectionFactory>();75 factory.Create(default(InjectionContext)).ReturnsForAnyArgs(new Dummy1());76 Container.Binder.Bind<IDummy>().ToFactory(factory);77 var instance1 = Container.Resolver.Resolve<IDummy>();78 var instance2 = Container.Resolver.Resolve<IDummy>();79 Assert.IsNotNull(instance1);80 Assert.IsNotNull(instance2);81 Assert.That(instance1, Is.EqualTo(instance2));82 Assert.That(instance1, Is.TypeOf<Dummy1>());83 Assert.That(instance2, Is.TypeOf<Dummy1>());84 factory.ReceivedWithAnyArgs(2).Create(default(InjectionContext));85 }86 [Test]87 public void BindAllToSingle()88 {89 Container.Binder.BindAll<Dummy1>().ToSelf().AsSingleton();90 var instance1 = Container.Resolver.Resolve<IDummy>();91 var instance2 = Container.Resolver.Resolve<Dummy1>();92 Assert.IsNotNull(instance1);93 Assert.IsNotNull(instance2);94 Assert.That(instance1, Is.EqualTo(instance2));95 Assert.That(instance1, Is.TypeOf<Dummy1>());96 Assert.That(instance2, Is.TypeOf<Dummy1>());97 }98 [Test]99 public void BindToStruct()100 {101 byte b = 1;102 Container.Binder.Bind<Dummy5, IDummy>().To<Dummy5>().AsTransient();103 Container.Binder.Bind<int>().ToSelf().AsSingleton();104 Container.Binder.Bind<long>().ToInstance(100L);105 Container.Binder.Bind<IConvertible>().To<float>().AsTransient();106 Container.Binder.Bind<IComparable>().ToMethod(c => b++).AsTransient();107 var instance = Container.Resolver.Resolve<Dummy5>();108 Assert.That(instance.Int, Is.EqualTo(0));109 Assert.That(instance.Long, Is.EqualTo(100L));110 Assert.That(instance.Float, Is.EqualTo(0f));...
PoolTests.cs
Source:PoolTests.cs
...14 {15 [Test]16 public void CreateSingle()17 {18 var pool = new Pool<Dummy1>();19 var instance = pool.Create();20 Assert.IsNotNull(instance);21 Assert.That(instance, Is.AssignableFrom<Dummy1>());22 }23 [Test]24 public void CreateMultiple()25 {26 var pool = new Pool<Dummy1>();27 var instance1 = pool.Create();28 var instance2 = pool.Create();29 Assert.IsNotNull(instance1);30 Assert.IsNotNull(instance2);31 Assert.That(instance1, Is.AssignableFrom<Dummy1>());32 Assert.That(instance2, Is.AssignableFrom<Dummy1>());33 Assert.That(instance1, !Is.EqualTo(instance2));34 }35 [Test]36 public void CreateWithFactory()37 {38 var factory = Substitute.For<IFactory<Dummy1>>();39 factory.Create().Returns(info => new Dummy1 { Value = 1 });40 var pool = new Pool<Dummy1>(factory);41 var instance = pool.Create();42 Assert.IsNotNull(instance);43 Assert.That(instance, Is.AssignableFrom<Dummy1>());44 Assert.That(instance.Value, Is.EqualTo(1));45 Received.InOrder(() => factory.Create());46 }47 [Test]48 public void CreateWithFactoryFunc()49 {50 var pool = new Pool<Dummy1>(() => new Dummy1 { Value = 1 });51 var instance = pool.Create();52 Assert.IsNotNull(instance);53 Assert.That(instance, Is.AssignableFrom<Dummy1>());54 Assert.That(instance.Value, Is.EqualTo(1));55 }56 [Test]57 public void CreateWithInitializer()58 {59 var initializer = new Dummy2Initializer();60 var pool = new Pool<Dummy2>(() => new Dummy2 { Value = 1 }, initializer);61 var instance = pool.Create();62 Assert.That(pool.Initializer, Is.EqualTo(initializer));63 Assert.IsNotNull(instance);64 Assert.That(instance, Is.AssignableFrom<Dummy2>());65 Assert.That(instance.Value, Is.EqualTo(2));66 pool.Recycle(instance);67 Assert.That(instance.Value, Is.EqualTo(3));68 }69 [Test]70 public void CreateWithInitializerAction()71 {72 var pool = new Pool<Dummy1>(() => new Dummy1 { Value = 1 }, d => d.Value = 2);73 var instance = pool.Create();74 Assert.IsNotNull(instance);75 Assert.That(instance, Is.AssignableFrom<Dummy1>());76 Assert.That(instance.Value, Is.EqualTo(2));77 }78 [Test]79 public void CreatePoolable()80 {81 var pool = new Pool<Dummy3>(() => new Dummy3 { Value = 1 });82 var instance1 = pool.Create();83 Assert.IsNotNull(instance1);84 Assert.That(instance1.Value, Is.EqualTo(2));85 pool.Recycle(instance1);86 Assert.That(instance1.Value, Is.EqualTo(3));87 var instance2 = pool.Create();88 Assert.IsNotNull(instance2);89 Assert.That(instance1, Is.EqualTo(instance2));90 Assert.That(instance2.Value, Is.EqualTo(2));91 pool.Recycle(instance2);92 Assert.That(instance2.Value, Is.EqualTo(3));93 }94 [Test]95 public void CreateNull()96 {97 var pool = new Pool<Dummy1>(() => null);98 Assert.That(pool.Storage.Count, Is.EqualTo(0));99 var instance1 = pool.Create();100 Assert.That(pool.Storage.Count, Is.EqualTo(0));101 Assert.IsFalse(pool.Recycle(instance1));102 Assert.That(pool.Storage.Count, Is.EqualTo(0));103 var instance2 = pool.Create();104 Assert.That(pool.Storage.Count, Is.EqualTo(0));105 Assert.IsFalse(pool.Recycle(instance2));106 Assert.That(pool.Storage.Count, Is.EqualTo(0));107 Assert.IsNull(instance1);108 Assert.IsNull(instance2);109 }110 [Test]111 public void RecycleSimple()112 {113 var pool = new Pool<Dummy1>();114 Assert.That(pool.Storage.Count, Is.EqualTo(0));115 var instance1 = pool.Create();116 Assert.That(pool.Storage.Count, Is.EqualTo(0));117 pool.Recycle(instance1);118 Assert.That(pool.Storage.Count, Is.EqualTo(1));119 var instance2 = pool.Create();120 Assert.That(pool.Storage.Count, Is.EqualTo(0));121 pool.Recycle(instance2);122 Assert.That(pool.Storage.Count, Is.EqualTo(1));123 Assert.IsNotNull(instance1);124 Assert.IsNotNull(instance2);125 Assert.That(instance1, Is.AssignableFrom<Dummy1>());126 Assert.That(instance2, Is.AssignableFrom<Dummy1>());127 Assert.That(instance1, Is.EqualTo(instance2));128 }129 [Test]130 public void RecycleDuplicate()131 {132 var pool = new Pool<Dummy1>();133 var instance = pool.Create();134 Assert.That(pool.Storage.Count, Is.EqualTo(0));135 Assert.IsTrue(pool.Recycle(instance));136 Assert.That(pool.Storage.Count, Is.EqualTo(1));137 Assert.IsFalse(pool.Recycle(instance));138 Assert.That(pool.Storage.Count, Is.EqualTo(1));139 }140 [Test]141 public void RecycleNull()142 {143 var pool = new Pool<Dummy1>();144 Assert.That(pool.Storage.Count, Is.EqualTo(0));145 Assert.IsFalse(pool.Recycle(null));146 Assert.That(pool.Storage.Count, Is.EqualTo(0));147 }148 [Test]149 public void StorageFill()150 {151 var pool = new Pool<Dummy1>();152 pool.Storage.Fill(3);153 Assert.That(pool.Storage.Count, Is.EqualTo(3));154 pool.Create();155 Assert.That(pool.Storage.Count, Is.EqualTo(2));156 pool.Create();157 Assert.That(pool.Storage.Count, Is.EqualTo(1));158 pool.Create();159 Assert.That(pool.Storage.Count, Is.EqualTo(0));160 }161 [Test]162 public void StorageTrim()163 {164 var pool = new Pool<Dummy1>();165 pool.Storage.Fill(3);166 Assert.That(pool.Storage.Count, Is.EqualTo(3));167 pool.Storage.Trim(2);168 Assert.That(pool.Storage.Count, Is.EqualTo(2));169 pool.Storage.Capacity = 1;170 Assert.That(pool.Storage.Count, Is.EqualTo(1));171 pool.Create();172 Assert.That(pool.Storage.Count, Is.EqualTo(0));173 pool.Create();174 Assert.That(pool.Storage.Count, Is.EqualTo(0));175 pool.Create();176 Assert.That(pool.Storage.Count, Is.EqualTo(0));177 }178 [Test]179 public void StorageOverflow()180 {181 var pool = new Pool<Dummy1>();182 pool.Storage.Capacity = 1;183 var instance1 = pool.Create();184 Assert.That(pool.Storage.Count, Is.EqualTo(0));185 var instance2 = pool.Create();186 Assert.That(pool.Storage.Count, Is.EqualTo(0));187 pool.Recycle(instance1);188 Assert.That(pool.Storage.Count, Is.EqualTo(1));189 pool.Recycle(instance2);190 Assert.That(pool.Storage.Count, Is.EqualTo(1));191 var instance3 = pool.Create();192 Assert.That(pool.Storage.Count, Is.EqualTo(0));193 var instance4 = pool.Create();194 Assert.That(pool.Storage.Count, Is.EqualTo(0));195 Assert.IsNotNull(instance1);196 Assert.IsNotNull(instance2);197 Assert.IsNotNull(instance3);198 Assert.IsNotNull(instance4);199 Assert.That(instance1, Is.AssignableFrom<Dummy1>());200 Assert.That(instance2, Is.AssignableFrom<Dummy1>());201 Assert.That(instance3, Is.AssignableFrom<Dummy1>());202 Assert.That(instance4, Is.AssignableFrom<Dummy1>());203 Assert.That(instance1, !Is.EqualTo(instance2));204 Assert.That(instance1, Is.EqualTo(instance3));205 Assert.That(instance1, !Is.EqualTo(instance4));206 Assert.That(instance2, !Is.EqualTo(instance3));207 Assert.That(instance2, !Is.EqualTo(instance4));208 Assert.That(instance3, !Is.EqualTo(instance4));209 }210 [Test]211 public void PoolDefaultModules()212 {213 var pool = new Pool<Dummy2>();214 Assert.That(pool.Factory, Is.AssignableFrom<DefaultFactory<Dummy2>>());215 Assert.That(pool.Initializer, Is.AssignableFrom<Dummy2Initializer>());216 Assert.That(pool.Storage, Is.AssignableFrom<Storage<Dummy2>>());217 }218 public class Dummy1219 {220 public int Value;221 }222 public class Dummy2223 {224 public int Value;225 }226 public class Dummy3 : IPoolable227 {228 public int Value;229 public void OnCreate()230 {231 Value = 2;232 }...
OrdersViewModel.cs
Source:OrdersViewModel.cs
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Caliburn.Micro;7using InventoryData;8using System.Collections.ObjectModel;9namespace FinalAssignment.ViewModels10{11 class OrdersViewModel : Conductor<IScreen>.Collection.OneActive12 {13 private ObservableCollection<Order> icollection;14 private static Order SelectedItemInfo;15 public OrdersViewModel()16 {17 this.DisplayName = "View Orders";18 //Console.WriteLine("Wen through the Orders constructor!!!!!!");19 //Dummy data20 Order dummy1 = new Order();21 dummy1.OrderNumber = 1;22 dummy1.DatePlaced = DateTime.Today;23 User dumdum = new User();24 dumdum.Name = "Mike Jones";25 dumdum.Phone = "218-330-8004";26 dumdum.UserId = 1234;27 dummy1.Purchaser = dumdum;28 dummy1.TotalCost = 1000000;29 Order dummy2 = new Order();30 dummy2.OrderNumber = 2;31 dummy2.DatePlaced = DateTime.Today;32 User dumdum2 = new User();33 dumdum2.Name = "50 Cent";34 dumdum2.Phone = "435-754-8289";35 dumdum2.UserId = 5678;36 dummy2.Purchaser = dumdum2;37 dummy2.TotalCost = .50m;38 icollection = new ObservableCollection<Order>();39 icollection.Add(dummy1);40 icollection.Add(dummy2);41 //////////////////////////////////////////////////////42 Item thing1 = new Item();43 thing1.Name = "Adidas";44 thing1.Cost = 69.99m;45 thing1.ItemNumber = 71;46 thing1.OrderItems = dummy2.OrderItems;47 thing1.QuantityOnHand = 17;48 Item thing2 = new Item();49 thing2.Name = "Retro Jordan 13";50 thing2.Cost = 249.99m;51 thing2.ItemNumber = 13;52 thing2.OrderItems = dummy2.OrderItems;53 thing2.QuantityOnHand = 17;54 Item thing3 = new Item();55 thing3.Name = "Playstation 5";56 thing3.Cost = 499.99m;57 thing3.ItemNumber = 21;58 thing3.OrderItems = dummy2.OrderItems;59 thing3.QuantityOnHand = 17;60 OrderItem dumster1 = new OrderItem();61 dumster1.ItemNumber = thing1.ItemNumber;62 dumster1.Quantity = 5;63 dumster1.ItemCost = 41;64 dumster1.Item = thing1;65 dumster1.OrderNumber = dummy1.OrderNumber;66 dumster1.OrderItemNumber = thing1.ItemNumber;67 dumster1.Order = dummy1;68 OrderItem dumster2 = new OrderItem();69 dumster2.ItemNumber = thing1.ItemNumber;70 dumster2.Quantity = 9;71 dumster2.ItemCost = 70;72 dumster2.Item = thing2;73 dumster2.OrderNumber = dummy2.OrderNumber;74 dumster2.OrderItemNumber = thing2.ItemNumber;75 dumster2.Order = dummy1;76 OrderItem dumster3 = new OrderItem();77 dumster3.ItemNumber = thing3.ItemNumber;78 dumster3.Quantity = 9;79 dumster3.ItemCost = 70;80 dumster3.Item = thing3;81 dumster3.OrderNumber = dummy2.OrderNumber;82 dumster3.OrderItemNumber = thing3.ItemNumber;83 dumster3.Order = dummy1;84 //items = new ObservableCollection<Item>();85 dummy1.OrderItems.Add(dumster1);86 dummy2.OrderItems.Add(dumster2);87 dummy2.OrderItems.Add(dumster3);88 //orderItems = (ObservableCollection<OrderItem>)dummy1.OrderItems;89 orderItems = new ObservableCollection<OrderItem>();90 //foreach (OrderItem x in SelectedItemInfo.OrderItems)91 //{92 // orderItems.Add(x);93 //}94 }95 public ObservableCollection<Order> AllOrders96 {97 get98 {99 return icollection;100 }101 }102 protected override void OnActivate()103 {104 //base.OnActivate();105 Orders();106 107 }108 public void Orders()109 {110 //var ordersVM = IoC.Get<OrdersViewModel>();111 //IoC.Get<OrdersView>();112 //OnActivate(ordersVM);113 }114 //IEnumerable<Order> OrdersView115 //{116 // get { return icollection; }117 //}118 /////////////////////////////////////////////////////////////////119 private ObservableCollection<OrderItem> orderItems;120 private static ObservableCollection<OrderItem> tester;121 public Order SelectedItem122 {123 get124 {125 return SelectedItemInfo;126 }127 set128 {129 //SelectedItemInfo = new Order();130 SelectedItemInfo = value;131 NotifyOfPropertyChange("AllItems");132 }133 }134 public ObservableCollection<OrderItem> AllItems135 {136 get137 {138 if (SelectedItemInfo !=null)139 {140 //if (orderItems.Count != 0)141 //{142 // foreach (OrderItem x in orderItems)143 // {144 // orderItems.Remove(x);145 // if (orderItems.Count < 1)146 // {147 // break;148 // }149 // }150 //}151 orderItems = new ObservableCollection<OrderItem>();152 foreach (OrderItem x in SelectedItem.OrderItems)153 {154 orderItems.Add(x);155 156 }157 }158 159 160 return orderItems;161 }162 }163 }164}...
MatchTests.cs
Source:MatchTests.cs
1using UnityEngine;2using System;3using System.Linq;4using System.Collections;5using System.Collections.Generic;6using Pseudo;7using NUnit.Framework;8namespace Pseudo.Groupingz.Tests9{10 public class MatchTests : GroupingTestsBase11 {12 [Test]13 public void MatchAll()14 {15 var dummy1 = new Dummy();16 var dummy2 = new Dummy();17 var dummy3 = new Dummy();18 GroupManager.Register(dummy1, "Boba");19 GroupManager.Register(dummy1, "Fett");20 GroupManager.Register(dummy1, "Jango");21 GroupManager.Register(dummy2, "Fett");22 GroupManager.Register(dummy2, "Jango");23 GroupManager.Register(dummy3, "Jango");24 var group1 = GroupManager.GetGroup(MatchType.All);25 var group2 = GroupManager.GetGroup(MatchType.All, "Boba");26 var group3 = GroupManager.GetGroup(MatchType.All, "Boba", "Fett");27 var group4 = GroupManager.GetGroup(MatchType.All, "Fett", "Jango");28 var group5 = GroupManager.GetGroup(MatchType.All, "Boba", "Fett", "Jango");29 Assert.That(group1.Count, Is.EqualTo(3));30 Assert.That(group1[0], Is.SameAs(dummy1));31 Assert.That(group1[1], Is.SameAs(dummy2));32 Assert.That(group1[2], Is.SameAs(dummy3));33 Assert.That(group2.Count, Is.EqualTo(1));34 Assert.That(group2[0], Is.SameAs(dummy1));35 Assert.That(group3.Count, Is.EqualTo(1));36 Assert.That(group3[0], Is.SameAs(dummy1));37 Assert.That(group4.Count, Is.EqualTo(2));38 Assert.That(group4[0], Is.SameAs(dummy1));39 Assert.That(group4[1], Is.SameAs(dummy2));40 Assert.That(group5.Count, Is.EqualTo(1));41 Assert.That(group5[0], Is.SameAs(dummy1));42 }43 [Test]44 public void MatchAny()45 {46 var dummy1 = new Dummy();47 var dummy2 = new Dummy();48 var dummy3 = new Dummy();49 GroupManager.Register(dummy1, "Boba");50 GroupManager.Register(dummy1, "Fett");51 GroupManager.Register(dummy1, "Jango");52 GroupManager.Register(dummy2, "Fett");53 GroupManager.Register(dummy2, "Jango");54 GroupManager.Register(dummy3, "Jango");55 var group1 = GroupManager.GetGroup(MatchType.Any);56 var group2 = GroupManager.GetGroup(MatchType.Any, "Boba");57 var group3 = GroupManager.GetGroup(MatchType.Any, "Boba", "Fett");58 var group4 = GroupManager.GetGroup(MatchType.Any, "Fett", "Jango");59 var group5 = GroupManager.GetGroup(MatchType.Any, "Boba", "Fett", "Jango");60 Assert.That(group1.Count, Is.EqualTo(3));61 Assert.That(group1[0], Is.SameAs(dummy1));62 Assert.That(group1[1], Is.SameAs(dummy2));63 Assert.That(group1[2], Is.SameAs(dummy3));64 Assert.That(group2.Count, Is.EqualTo(1));65 Assert.That(group2[0], Is.SameAs(dummy1));66 Assert.That(group3.Count, Is.EqualTo(2));67 Assert.That(group3[0], Is.SameAs(dummy1));68 Assert.That(group3[1], Is.SameAs(dummy2));69 Assert.That(group4.Count, Is.EqualTo(3));70 Assert.That(group4[0], Is.SameAs(dummy1));71 Assert.That(group4[1], Is.SameAs(dummy2));72 Assert.That(group4[2], Is.SameAs(dummy3));73 Assert.That(group5.Count, Is.EqualTo(3));74 Assert.That(group5[0], Is.SameAs(dummy1));75 Assert.That(group5[1], Is.SameAs(dummy2));76 Assert.That(group5[2], Is.SameAs(dummy3));77 }78 [Test]79 public void MatchNone()80 {81 var dummy1 = new Dummy();82 var dummy2 = new Dummy();83 var dummy3 = new Dummy();84 GroupManager.Register(dummy1, "Boba");85 GroupManager.Register(dummy1, "Fett");86 GroupManager.Register(dummy1, "Jango");87 GroupManager.Register(dummy2, "Fett");88 GroupManager.Register(dummy2, "Jango");89 GroupManager.Register(dummy3, "Jango");90 var group1 = GroupManager.GetGroup(MatchType.None);91 var group2 = GroupManager.GetGroup(MatchType.None, "Boba");92 var group3 = GroupManager.GetGroup(MatchType.None, "Boba", "Fett");93 var group4 = GroupManager.GetGroup(MatchType.None, "Fett", "Jango");94 var group5 = GroupManager.GetGroup(MatchType.None, "Boba", "Fett", "Jango");95 Assert.That(group1.Count, Is.EqualTo(0));96 Assert.That(group2.Count, Is.EqualTo(2));97 Assert.That(group2[0], Is.SameAs(dummy2));98 Assert.That(group2[1], Is.SameAs(dummy3));99 Assert.That(group3.Count, Is.EqualTo(1));100 Assert.That(group3[0], Is.SameAs(dummy3));101 Assert.That(group4.Count, Is.EqualTo(0));102 Assert.That(group5.Count, Is.EqualTo(0));103 }104 [Test]105 public void MatchExact()106 {107 var dummy1 = new Dummy();108 var dummy2 = new Dummy();109 var dummy3 = new Dummy();110 GroupManager.Register(dummy1, "Boba");111 GroupManager.Register(dummy1, "Fett");112 GroupManager.Register(dummy1, "Jango");113 GroupManager.Register(dummy2, "Fett");114 GroupManager.Register(dummy2, "Jango");115 GroupManager.Register(dummy3, "Jango");116 var group1 = GroupManager.GetGroup(MatchType.Exact);117 var group2 = GroupManager.GetGroup(MatchType.Exact, "Boba");118 var group3 = GroupManager.GetGroup(MatchType.Exact, "Boba", "Fett");119 var group4 = GroupManager.GetGroup(MatchType.Exact, "Fett", "Jango");120 var group5 = GroupManager.GetGroup(MatchType.Exact, "Boba", "Fett", "Jango");121 Assert.That(group1.Count, Is.EqualTo(0));122 Assert.That(group2.Count, Is.EqualTo(0));123 Assert.That(group3.Count, Is.EqualTo(0));124 Assert.That(group4.Count, Is.EqualTo(1));125 Assert.That(group4[0], Is.SameAs(dummy2));126 Assert.That(group5.Count, Is.EqualTo(1));127 Assert.That(group5[0], Is.SameAs(dummy1));128 }129 }130}...
InsertFixture.cs
Source:InsertFixture.cs
1using System;2using System.Transactions;3using BoC.Events;4using BoC.Persistence;5using Moq;6using Xunit;78namespace BoC.Tests.Services.BaseModelServiceFixtures9{10 public class InsertFixture: BaseModelServiceBaseFixture11 {1213 [Fact]14 public void Insert_Should_Save_To_Repository()15 {16 eventAggregator.Setup(ev => ev.GetEvent<InsertingEvent<DummyModel>>()).Returns(new InsertingEvent<DummyModel>());17 eventAggregator.Setup(ev => ev.GetEvent<InsertedEvent<DummyModel>>()).Returns(new InsertedEvent<DummyModel>());1819 service.Object.Insert(dummy1);2021 repository.Verify(r => r.Save(dummy1), Times.Once());22 }2324 [Fact]25 public void Insert_Should_Return_Repository_Result()26 {27 eventAggregator.Setup(ev => ev.GetEvent<InsertingEvent<DummyModel>>()).Returns(new InsertingEvent<DummyModel>());28 eventAggregator.Setup(ev => ev.GetEvent<InsertedEvent<DummyModel>>()).Returns(new InsertedEvent<DummyModel>());29 30 repository.Setup(r => r.Save(It.IsAny<DummyModel>())).Callback<DummyModel>(entity => entity.Saved = true).Returns(dummy1);3132 Assert.False(dummy1.Saved);33 var result = service.Object.Insert(dummy1);3435 Assert.True(result.Saved);36 }3738 [Fact]39 public void Insert_Should_Trigger_InsertingEvent_Before_Inserting()40 {41 var insertEvent = new Mock<InsertingEvent<DummyModel>>();42 43 eventAggregator.Setup(ev => ev.GetEvent<InsertingEvent<DummyModel>>()).Returns(insertEvent.Object).Verifiable();44 eventAggregator.Setup(ev => ev.GetEvent<InsertedEvent<DummyModel>>()).Returns(new InsertedEvent<DummyModel>());4546 repository.Setup(r => r.Save(It.IsAny<DummyModel>())).Callback<DummyModel>(entity => entity.Saved = true);47 insertEvent48 .Setup(ev => ev.Publish(It.IsAny<EventArgs<DummyModel>>()))49 .Callback<EventArgs<DummyModel>>(args =>50 {51 Assert.Equal(dummy1, args.Item);52 Assert.False(args.Item.Saved); //oninserting should be called before actual save53 }).Verifiable();54 Assert.False(dummy1.Saved);55 service.Object.Insert(dummy1);5657 eventAggregator.Verify();58 insertEvent.Verify();59 }6061 [Fact]62 public void Insert_Should_Not_Insert_If_InsertingEvent_Throws_Error()63 {64 var insertEvent = new Mock<InsertingEvent<DummyModel>>();6566 eventAggregator.Setup(ev => ev.GetEvent<InsertingEvent<DummyModel>>()).Returns(insertEvent.Object).Verifiable();67 eventAggregator.Setup(ev => ev.GetEvent<InsertedEvent<DummyModel>>()).Returns(new InsertedEvent<DummyModel>());6869 repository.Setup(r => r.Save(It.IsAny<DummyModel>())).Callback<DummyModel>(entity => entity.Saved = true);70 insertEvent71 .Setup(ev => ev.Publish(It.IsAny<EventArgs<DummyModel>>()))72 .Callback<EventArgs<DummyModel>>(args => { throw new Exception(); })73 .Verifiable();74 75 Assert.False(dummy1.Saved);76 Assert.Throws<Exception>(() => service.Object.Insert(dummy1));77 Assert.False(dummy1.Saved);78 eventAggregator.Verify();79 insertEvent.Verify();80 repository.Verify(r => r.Save(It.IsAny<DummyModel>()), Times.Never());81 }8283 [Fact]84 public void Insert_Should_Happen_Within_Transaction()85 {86 var insertingEvent = new Mock<InsertingEvent<DummyModel>>();87 var insertedEvent = new Mock<InsertedEvent<DummyModel>>();88 eventAggregator.Setup(ev => ev.GetEvent<InsertingEvent<DummyModel>>()).Returns(insertingEvent.Object).Verifiable();89 eventAggregator90 .Setup(ev => ev.GetEvent<InsertedEvent<DummyModel>>())91 .Returns(insertedEvent.Object).Verifiable();9293 repository.Setup(r => r.Save(It.IsAny<DummyModel>()))94 .Callback<DummyModel>(entity => Assert.True(Transaction.Current.TransactionInformation.Status == TransactionStatus.Active));95 96 insertedEvent97 .Setup(ev => ev.Publish(It.IsAny<EventArgs<DummyModel>>()))98 .Callback(() => Assert.True(Transaction.Current.TransactionInformation.Status == TransactionStatus.Active))99 .Verifiable();100 insertingEvent101 .Setup(ev => ev.Publish(It.IsAny<EventArgs<DummyModel>>()))102 .Callback(() => Assert.True(Transaction.Current.TransactionInformation.Status == TransactionStatus.Active))103 .Verifiable();104105 service.Object.Insert(dummy1);106107 eventAggregator.Verify();108 insertingEvent.Verify();109 insertedEvent.Verify();110 }111 }
...
MultiPoolTests.cs
Source:MultiPoolTests.cs
...15 [Test]16 public void CreateWithInheritance()17 {18 var multiPool = new MultiPool<IDummy>();19 var instance1 = multiPool.Create<Dummy1>();20 var instance2 = multiPool.Create(typeof(Dummy2));21 Assert.IsNotNull(instance1);22 Assert.IsNotNull(instance2);23 Assert.That(instance1, Is.AssignableFrom<Dummy1>());24 Assert.That(instance2, Is.AssignableFrom<Dummy2>());25 }26 [Test]27 public void RecycleWithInheritance()28 {29 var multiPool = new MultiPool<IDummy>();30 var instance1 = multiPool.Create<Dummy1>();31 var instance2 = multiPool.Create(typeof(Dummy2));32 multiPool.Recycle(instance1);33 multiPool.Recycle(instance2);34 var instance3 = multiPool.Create(typeof(Dummy1));35 var instance4 = multiPool.Create<Dummy2>();36 multiPool.Recycle(instance3);37 multiPool.Recycle(instance4);38 Assert.IsNotNull(instance1);39 Assert.IsNotNull(instance2);40 Assert.IsNotNull(instance3);41 Assert.IsNotNull(instance4);42 Assert.That(instance1, !Is.EqualTo(instance2));43 Assert.That(instance1, Is.EqualTo(instance3));44 Assert.That(instance1, !Is.EqualTo(instance4));45 Assert.That(instance2, !Is.EqualTo(instance3));46 Assert.That(instance2, Is.EqualTo(instance4));47 Assert.That(instance3, !Is.EqualTo(instance4));48 Assert.That(multiPool.GetPool<Dummy1>().Storage.Count, Is.EqualTo(1));49 Assert.That(multiPool.GetPool(typeof(Dummy2)).Storage.Count, Is.EqualTo(1));50 }51 [Test]52 public void CreateWithRegisteredPools()53 {54 var pool1 = new Pool<Dummy1>();55 var pool2 = new Pool<Dummy2>();56 var multiPool = new MultiPool<IDummy>(pool1);57 multiPool.AddPool(pool2);58 Assert.IsTrue(multiPool.ContainsPool(typeof(Dummy1)));59 Assert.IsTrue(multiPool.ContainsPool<Dummy2>());60 Assert.IsFalse(multiPool.ContainsPool<IDummy>());61 }62 [Test]63 public void CreateWithPoolFactory()64 {65 var factory = new DummyPoolFactory();66 var multiPool = new MultiPool<IDummy>(factory);67 var instance1 = multiPool.Create<Dummy1>();68 var instance2 = multiPool.Create<Dummy2>();69 Assert.IsNotNull(instance1);70 Assert.IsNotNull(instance2);71 Assert.That(instance1.Value, Is.EqualTo(1));72 Assert.That(instance2.Value, Is.EqualTo(2));73 }74 [Test]75 public void CreateWithPoolFactoryFunc()76 {77 var multiPool = new MultiPool<IDummy>(t =>78 {79 if (t.Is<Dummy1>())80 return new Pool<Dummy1>(() => new Dummy1 { Value = 1 });81 else if (t.Is<Dummy2>())82 return new Pool<Dummy2>(() => new Dummy2 { Value = 2 });83 else84 return new Pool<IDummy>(() => null);85 });86 var instance1 = multiPool.Create<Dummy1>();87 var instance2 = multiPool.Create<Dummy2>();88 Assert.IsNotNull(instance1);89 Assert.IsNotNull(instance2);90 Assert.That(instance1.Value, Is.EqualTo(1));91 Assert.That(instance2.Value, Is.EqualTo(2));92 }93 [Test]94 public void AddContainRemoveClearPool()95 {96 var pool1 = new Pool<Dummy1>();97 IPool pool2 = new Pool<Dummy2>();98 var multiPool = new MultiPool<Dummy1>(pool1);99 Assert.That(multiPool.PoolCount, Is.EqualTo(1));100 Assert.IsFalse(multiPool.AddPool(pool2));101 Assert.IsTrue(multiPool.ContainsPool<Dummy1>());102 Assert.IsFalse(multiPool.ContainsPool(typeof(Dummy2)));103 Assert.IsFalse(multiPool.ContainsPool(typeof(IDummy)));104 multiPool.RemovePool<Dummy1>();105 Assert.That(multiPool.PoolCount, Is.EqualTo(0));106 Assert.IsFalse(multiPool.ContainsPool(typeof(Dummy1)));107 Assert.IsTrue(multiPool.AddPool(pool1));108 Assert.That(multiPool.PoolCount, Is.EqualTo(1));109 Assert.IsTrue(multiPool.ContainsPool<Dummy1>());110 multiPool.ClearPools();111 Assert.That(multiPool.PoolCount, Is.EqualTo(0));112 Assert.IsFalse(multiPool.ContainsPool<Dummy1>());113 }114 public interface IDummy { }115 public class Dummy1 : IDummy116 {117 public int Value;118 }119 public class Dummy2 : IDummy120 {121 public int Value;122 }123 public class DummyPoolFactory : PoolFactoryBase124 {125 public override IPool Create(Type argument)126 {127 if (argument.Is<Dummy1>())128 return new Pool<Dummy1>(() => new Dummy1 { Value = 1 });129 else if (argument.Is<Dummy2>())130 return new Pool<Dummy2>(() => new Dummy2 { Value = 2 });131 else132 return new Pool<IDummy>(() => null);133 }134 }135 }136}...
Grenade2.cs
Source:Grenade2.cs
...41 public void ConfirmRecipe()42 {43 var world = base.Setup("items.yaml",itemYaml,"blast.injury.yaml",injurySystemYaml);44 var grenade = world.Player.SpawnItem("Grenade");45 var dummy1 = new Npc("Target Dummy1",world.Player.CurrentLocation);46 var dummy2 = new Npc("Target Dummy2",world.Player.CurrentLocation);47 48 //Don't wander off or anything49 dummy1.BaseActions.Clear();50 dummy2.BaseActions.Clear();51 dummy1.BaseBehaviours.Clear();52 dummy2.BaseBehaviours.Clear();53 Assert.AreEqual(0,world.Relationships.SumBetween(dummy1,world.Player), "To start with nobody should be angry");54 Assert.AreEqual(0,world.Relationships.SumBetween(dummy2,world.Player), "To start with nobody should be angry");55 Assert.IsTrue(world.Player.Items.Single().Name.Equals("Grenade"));56 RunRound(world,"Fight [Grenade(1)]",dummy1);57 Assert.IsTrue(grenade.IsErased);58 Assert.IsEmpty(world.Player.Items,"Expected grenade to be used and now gone");59 //splash damage hit + initial hit...
InstantiateTests.cs
Source:InstantiateTests.cs
1using UnityEngine;2using System;3using System.Linq;4using System.Collections;5using System.Collections.Generic;6using Pseudo;7using NUnit.Framework;8namespace Pseudo.Injection.Tests9{10 public class InstantiateTests : InjectionTestsBase11 {12 [Test]13 public void Instantiate()14 {15 var dummy1 = Container.Instantiator.Instantiate<DummySubField>();16 var dummy2 = Container.Instantiator.Instantiate<DummySubProperty>();17 Assert.IsNotNull(dummy1);18 Assert.IsNotNull(dummy2);19 }20 [Test]21 public void InstantiateWithDefaultValues()22 {23 var dummy1 = Container.Get<InstantiateDummyWithDefaultValues>();24 Assert.IsNotNull(dummy1);25 Assert.That(dummy1.Integer, Is.EqualTo(1));26 Assert.That(dummy1.Single, Is.EqualTo(2f));27 Assert.That(dummy1.Reference, Is.EqualTo(null));28 }29 //[Test]30 //public void InstantiateWithArguments()31 //{32 // var dummy1 = Container.Instantiator.Instantiate<InstantiateDummy>((short)1, 2, true);33 // var dummy2 = Container.Instantiator.Instantiate<InstantiateDummy>((byte)3, null, null);34 // Assert.IsNotNull(dummy1);35 // Assert.IsNotNull(dummy2);36 // Assert.That(dummy1, !Is.EqualTo(dummy2));37 // Assert.That(dummy1.Integer, Is.EqualTo(1));38 // Assert.That(dummy1.Single, Is.EqualTo(2));39 // Assert.That(dummy1.Boolean, Is.EqualTo(true));40 // Assert.That(dummy2.Integer, Is.EqualTo(3));41 // Assert.That(dummy2.Single, Is.EqualTo(0f));42 // Assert.That(dummy2.Boolean, Is.EqualTo(false));43 //}44 public class InstantiateDummy45 {46 public readonly int Integer;47 public readonly float Single;48 public readonly bool Boolean;49 public InstantiateDummy() { }50 public InstantiateDummy(int integer, float single, bool boolean)51 {52 Integer = integer;53 Single = single;54 Boolean = boolean;55 }56 }57 public class InstantiateDummyWithDefaultValues58 {59 public readonly int Integer;60 public readonly float Single;61 public readonly object Reference;62 public InstantiateDummyWithDefaultValues(int integer = 1, float single = 2f, object reference = null)63 {64 Integer = integer;65 Single = single;66 Reference = reference;67 }68 }69 }70}...
Dummy1
Using AI Code Generation
1B.Dummy1 d1 = new B.Dummy1();2d1.Print();3B.Dummy2 d2 = new B.Dummy2();4d2.Print();5A.Dummy1 d3 = new A.Dummy1();6d3.Print();7A.Dummy2 d4 = new A.Dummy2();8d4.Print();9B.Dummy1 d1 = new B.Dummy1();10d1.Print();11B.Dummy2 d2 = new B.Dummy2();12d2.Print();13A.Dummy1 d3 = new A.Dummy1();14d3.Print();15A.Dummy2 d4 = new A.Dummy2();16d4.Print();17B.Dummy1 d1 = new B.Dummy1();18d1.Print();19B.Dummy2 d2 = new B.Dummy2();20d2.Print();21A.Dummy1 d3 = new A.Dummy1();22d3.Print();23A.Dummy2 d4 = new A.Dummy2();24d4.Print();25B.Dummy1 d1 = new B.Dummy1();26d1.Print();27B.Dummy2 d2 = new B.Dummy2();28d2.Print();29A.Dummy1 d3 = new A.Dummy1();30d3.Print();31A.Dummy2 d4 = new A.Dummy2();32d4.Print();33B.Dummy1 d1 = new B.Dummy1();34d1.Print();
Dummy1
Using AI Code Generation
1B.Dummy1 d1 = new B.Dummy1();2d1.DoSomething();3B.Dummy2 d2 = new B.Dummy2();4d2.DoSomething();5C.Dummy1 d1 = new C.Dummy1();6d1.DoSomething();7C.Dummy2 d2 = new C.Dummy2();8d2.DoSomething();
Dummy1
Using AI Code Generation
1using B;2Dummy1 d1 = new Dummy1();3using B;4Dummy2 d2 = new Dummy2();5using B;6Dummy3 d3 = new Dummy3();7using B;8Dummy4 d4 = new Dummy4();9using B;10Dummy5 d5 = new Dummy5();11using B;12Dummy6 d6 = new Dummy6();13using B;14Dummy7 d7 = new Dummy7();15using B;16Dummy8 d8 = new Dummy8();17using B;18Dummy9 d9 = new Dummy9();19using B;20Dummy10 d10 = new Dummy10();21using B;22Dummy11 d11 = new Dummy11();23using B;24Dummy12 d12 = new Dummy12();25using B;26Dummy13 d13 = new Dummy13();27using B;28Dummy14 d14 = new Dummy14();29using B;30Dummy15 d15 = new Dummy15();31using B;32Dummy16 d16 = new Dummy16();
Dummy1
Using AI Code Generation
1using B;2{3 public static void Main()4 {5 Dummy1 d1 = new Dummy1();6 d1.Show();7 }8}9using A;10{11 public static void Main()12 {13 Dummy2 d2 = new Dummy2();14 d2.Main();15 }16}17Microsoft (R) Visual C# Compiler version 1.0.3705.601818for Microsoft (R) .NET Framework version 1.0.3705.6018191.cs(5,6): warning CS0108: `B.Dummy1' hides inherited member `A.Dummy1'. Use201.cs(9,9): warning CS0108: `B.Dummy1.Show()' hides inherited member `A.Dummy121.Show()'. Use the new keyword if hiding was intended221.cs(21,6): warning CS0108: `A.Dummy2' hides inherited member `B.Dummy2'. Use231.cs(25,9): warning CS0108: `A.Dummy2.Main()' hides inherited member `B.Dummy224.Main()'. Use the new keyword if hiding was intended251 Warning(s)264 Error(s)27Microsoft (R) Visual C# Compiler version 1.0.3705.601828for Microsoft (R) .NET Framework version 1.0.3705.6018292.cs(5,6): warning CS0108: `B.Dummy1' hides inherited member `A.Dummy1'. Use302.cs(9,9): warning CS0108: `B.Dummy1.Show()' hides inherited member `A.Dummy131.Show()'. Use the new keyword if hiding was intended322.cs(21,6): warning CS0108: `A.Dummy2' hides inherited member `B.Dummy2'. Use332.cs(25,9): warning
Dummy1
Using AI Code Generation
1using A;2using B;3{4 {5 public static void Main()6 {7 Dummy1 d1 = new Dummy1();8 d1.Print();9 Dummy2 d2 = new Dummy2();10 d2.Print();11 }12 public void Print()13 {14 System.Console.WriteLine("Hello from Dummy2");15 }16 }17}
Dummy1
Using AI Code Generation
1using B;2{3 public static void Main()4 {5 Dummy1 d = new Dummy1();6 d.Print();7 }8}9using C;10{11 public static void Main()12 {13 Dummy1 d = new Dummy1();14 d.Print();15 }16}17using D;18{19 public static void Main()20 {21 Dummy1 d = new Dummy1();22 d.Print();23 }24}25using E;26{27 public static void Main()28 {29 Dummy1 d = new Dummy1();30 d.Print();31 }32}33using F;34{35 public static void Main()36 {37 Dummy1 d = new Dummy1();38 d.Print();39 }40}41using G;42{43 public static void Main()44 {45 Dummy1 d = new Dummy1();46 d.Print();47 }48}49using H;50{51 public static void Main()52 {53 Dummy1 d = new Dummy1();54 d.Print();55 }56}57using I;58{59 public static void Main()60 {61 Dummy1 d = new Dummy1();62 d.Print();63 }64}65using J;66{67 public static void Main()68 {69 Dummy1 d = new Dummy1();70 d.Print();71 }72}73using K;74{75 public static void Main()76 {77 Dummy1 d = new Dummy1();78 d.Print();79 }80}
Dummy1
Using AI Code Generation
1using B;2{3 {4 public static void Main()5 {6 Dummy1 d1 = new Dummy1();7 d1.show();8 }9 }10}11using namespace_name;12using System;13{14 {15 public void show()16 {17 Console.WriteLine("Dummy1");18 }19 }20}21using System;22using A;23{24 {25 public static void Main()26 {27 Dummy1 d1 = new Dummy1();28 d1.show();29 }30 }31}32using namespace_name = alias_name;33using System;34using A = System.Collections;35{36 {37 public void show()38 {39 Console.WriteLine("Dummy1");40 }41 }42}43using System;44using B;45{46 {47 public static void Main()48 {49 Dummy1 d1 = new Dummy1();50 d1.show();51 }52 }53}
Dummy1
Using AI Code Generation
1{2 d1.display();3}4{5 d1.display();6}7B.Dummy1.display()8A.Dummy1.display()9A.Dummy1.display()
Dummy1
Using AI Code Generation
1using B;2{3 static void Main()4 {5 Dummy1 obj1 = new Dummy1();6 obj1.show();7 }8}9using B;10{11 static void Main()12 {13 B.Dummy1 obj1 = new B.Dummy1();14 obj1.show();15 }16}
Nunit is a well-known open-source unit testing framework for C#. This framework is easy to work with and user-friendly. LambdaTest’s NUnit Testing Tutorial provides a structured and detailed learning environment to help you leverage knowledge about the NUnit framework. The NUnit tutorial covers chapters from basics such as environment setup to annotations, assertions, Selenium WebDriver commands, and parallel execution using the NUnit framework.
You can also check out the LambdaTest Certification to enhance your learning in Selenium Automation Testing using the NUnit framework.
Watch this tutorial on the LambdaTest Channel to learn how to set up the NUnit framework, run tests and also execute parallel testing.
Get 100 minutes of automation test minutes FREE!!