当前位置: 首页>>代码示例>>C#>>正文


C# Fixture.CreateMany方法代码示例

本文整理汇总了C#中Fixture.CreateMany方法的典型用法代码示例。如果您正苦于以下问题:C# Fixture.CreateMany方法的具体用法?C# Fixture.CreateMany怎么用?C# Fixture.CreateMany使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fixture的用法示例。


在下文中一共展示了Fixture.CreateMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageShouldBeSameAfterSerializationAndDeserialization

        public void MessageShouldBeSameAfterSerializationAndDeserialization()
        {
            var writer = new BinaryWriter(new MemoryStream());
            IMessageFactory msgFactory = new MessageFactory(new Message[]
                {
                    new ISomeServiceComplexRequest()
                });

            var fixture = new Fixture();
            fixture.Customize<ISomeServiceComplexRequest>(ob =>
                ob.With(x => x.datas,
                    fixture.CreateMany<SubData>().ToList()));
            fixture.Customize<ComplexData>(ob => ob
                .With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
                .With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));

            var msg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();

            //serialize and deserialize msg1
            msg.Serialize(writer);
            writer.Seek(0, SeekOrigin.Begin);
            var reader = new BinaryReader(writer.BaseStream);
            Message retMsg = msgFactory.Deserialize(reader);

            retMsg.Should().BeOfType<ISomeServiceComplexRequest>();
            msg.ShouldBeEqualTo((ISomeServiceComplexRequest)retMsg);
        }
开发者ID:tlotter,项目名称:MassiveOnlineUniversalServerEngine,代码行数:27,代码来源:MessageSerializationTests.cs

示例2: CreateTestDataIn

        private static void CreateTestDataIn(Database db)
        {
            var createRole = new CreateRole
            {
                Name = "Admin",
                Permissions = new[] {"View Users", "Edit Users", "Deactivate Users"}
            };
            db.CreateRole(createRole);
            db.CreateUser(new CreateUser {FullName = "Dan Barua", UserName = "dan", RoleId = createRole.Id.GetValueOrDefault()});
            db.CreateUser(new CreateUser {FullName = "Jonathon Channon", UserName = "jonathon", RoleId = createRole.Id.GetValueOrDefault()});

            // let's generate some random data!
            var fixture = new Fixture {RepeatCount = 100};

            var roles = fixture.CreateMany<CreateRole>().ToList();
            var users = fixture.CreateMany<CreateUser>().ToList();
            foreach (var r in roles)
            {
                db.CreateRole(r);
            }

            var roleCount = roles.Count();
            foreach (var u in users)
            {
                u.RoleId = roles.Skip(new Random().Next(0, roleCount)).Take(1).First().Id.GetValueOrDefault();
                // select random id from roles
                db.CreateUser(u);
            }
        }
开发者ID:dealproc,项目名称:Nancy.Hal,代码行数:29,代码来源:ExampleBootstrapper.cs

示例3: Create

            public static TestData Create(int stepCount, int machinesPerStep)
            {
                var fixture = new Fixture();
                var returnValue = new TestData
                {
                    DeployBatchRequest = fixture.Build<DeployBatchRequest>()
                                    .With(i=>i.ItemList,
                                            fixture.Build<DeployBatchRequestItem>()
                                                .With(j=>j.MachineList, fixture.CreateMany<DeployMachine>(machinesPerStep).ToList())
                                                .CreateMany(stepCount).ToList())
                                    .Create(),
                    ProjectManager = new Mock<IProjectManager>()
                };
                var deployMachineNameList = fixture.CreateMany("DeployMachineName", machinesPerStep).ToList();
                foreach(var item in returnValue.DeployBatchRequest.ItemList)
                {
                    for(int i = 0; i < machinesPerStep; i++)
                    {
                        item.MachineList[i].MachineName = deployMachineNameList[i];
                    }
                }
                returnValue.Sut = new DeploymentPlanBuilder(returnValue.ProjectManager.Object);

                return returnValue;
            }
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:25,代码来源:DeploymentPlanBuilderTests.cs

示例4: ShouldProperlyInvokeRequestReplyMethod

        public void ShouldProperlyInvokeRequestReplyMethod()
        {
            #region Arrange
            var fixture = new Fixture();
            fixture.Customize<ISomeServiceComplexRequest>(ob =>
                ob.With(x => x.datas,
                    fixture.CreateMany<SubData>().ToList()));
            fixture.Customize<ComplexData>(ob => ob
                .With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
                .With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));

            var inputMsg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();
            var output = inputMsg.data;

            var tcs = new TaskCompletionSource<ComplexData>();
            tcs.SetResult(output);

            var service = Substitute.For<ISomeService>();
            service.Complex(inputMsg.requestId, inputMsg.data, inputMsg.name, inputMsg.datas)
                .Returns(x => tcs.Task);

            #endregion

            //Act
            Task<Message> ret = _protocolDesc.Dispatch(service, inputMsg);

            //Assert
            service.Received(1).Complex(inputMsg.requestId, inputMsg.data, inputMsg.name, inputMsg.datas);
            ret.Should().NotBeNull();
            ret.Status.Should().Be(TaskStatus.RanToCompletion);
            var replyMsg = ret.Result as ISomeServiceComplexReply;
            replyMsg.Should().NotBeNull();
            replyMsg.RetVal.Should().Be(output);
        }
开发者ID:tlotter,项目名称:MassiveOnlineUniversalServerEngine,代码行数:34,代码来源:DispatcherTests.cs

示例5: SetUp

        protected override sealed void SetUp()
        {
            base.SetUp();

            var fixture = new Fixture();

            _sources = fixture.CreateMany<IEnumerable<int>>().ToArray();
            _comparer = new TestComparer();

            for (var i = 0; i < _sources.Length; i++) {
                _sources[i] = fixture.CreateMany<int>().OrderBy(item => item);
            }
        }
开发者ID:KBurov,项目名称:Helpers,代码行数:13,代码来源:Context.cs

示例6: GetPatientTherapies

        public IEnumerable<PatientTherapy> GetPatientTherapies(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientTherapies)
        {
            fixture.Customize<PatientTherapy>(pt => pt.With(x => x.PatientId, demographic.PatientId)
                                                      .Without(x => x.DDID)
                                                      .Without(x => x.RXNorm)
                                                      .Without(x => x.StopDate));

            var therapies = fixture.CreateMany<PatientTherapy>(randomizer.Next(0, maxNumberOfPatientTherapies + 1));
            foreach (var therapy in therapies)
            {
                var daysOnTherapy = randomizer.Next(1, 365);
                therapy.StopDate = new DateTime(Math.Min(therapy.StartDate.AddDays(daysOnTherapy).Ticks, DateTime.Now.Ticks));

                var hasFavoredTherapy = randomizer.NextPercent() <= ChanceOfHavingFavoredCondition;
                if (hasFavoredTherapy)
                {
                    var pair = randomizer.NextDictionaryPair(_favoredTherapies);
                    therapy.NDC = pair.Key;
                    therapy.DrugName = pair.Value;
                }
                else
                {
                    therapy.NDC = NDCGenerator.GetRandomNDC(randomizer);
                }
            }

            return therapies.OrderBy(x => x.StartDate);
        }
开发者ID:ryanpeelman,项目名称:EMRG,代码行数:28,代码来源:PatientTherapyBuilder.cs

示例7: FreshenMailBoxTestWithException

        public void FreshenMailBoxTestWithException()
        {
            _imapWorker.Setup(false);

            var r = new ImapCommandResponse();

            var fix = new Fixture();
            fix.Customize(new AutoMoqCustomization());

            var messages = fix.CreateMany<IMessageSummary>().ToList();

            //first fetch throws exception - after closing and opening folders now messages are returned
            //this mirrors how the client has been functioning in real world tests
            inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(),
                It.IsAny<CancellationToken>())).ThrowsAsync(new ImapCommandException(r ,"The IMAP server replied to the 'FETCH' command with a 'NO' response."))
                .Callback(() =>
                {
                    inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(),
                        It.IsAny<CancellationToken>())).ReturnsAsync(messages);
                });

            _imapWorker.FreshenMailBox();

            inbox.Verify(x => x.CloseAsync(It.Is<bool>(y => y == false), It.IsAny<CancellationToken>()), Times.Exactly(1));
            inbox.Verify(x => x.OpenAsync(It.IsAny<FolderAccess>(), It.IsAny<CancellationToken>()));
        }
开发者ID:ptfuller,项目名称:InboxWatcher,代码行数:26,代码来源:ImapWorkerTests.cs

示例8: IndexWillReturnViewModelWithCorrectProducts

        public void IndexWillReturnViewModelWithCorrectProducts()
        {
            // Fixture setup
            var fixture = new Fixture().Customize(new CommerceWebCustomization());
            var featuredProducts =
                fixture.CreateMany<Product>().ToList();
            fixture.Register(() =>
                {
                    var repositoryStub =
                        new Mock<ProductRepository>();
                    repositoryStub.Setup(r =>
                        r.GetFeaturedProducts())
                        .Returns(featuredProducts);
                    return repositoryStub.Object;
                });

            var expectedProducts = (from p in featuredProducts
                                    select new Likeness<Product, ProductViewModel>(p).Without(d => d.SummaryText)).ToList();

            var sut =
                fixture.CreateAnonymous<HomeController>();
            // Exercise system
            var result = ((FeaturedProductsViewModel)sut
                .Index().ViewData.Model).Products.ToList();
            // Verify outcome
            Assert.True(expectedProducts.Cast<object>().SequenceEqual(result.Cast<object>()));
            // Teardown
        }
开发者ID:mesta1,项目名称:dli.net_sourcecode,代码行数:28,代码来源:HomeControllerTest.cs

示例9: IsEnabledCallsAllToggles

        public void IsEnabledCallsAllToggles([Frozen] IFeatureToggleProvider toggleProvider, IFeature feature,
            Fixture fixture, FeatureContext sut)
        {
            var featureToggles = fixture.CreateMany<Fake<IFeatureToggle>>().ToList();
            foreach (Fake<IFeatureToggle> fake in featureToggles)
            {
                fake.CallsTo(ft => ft.IsEnabled(feature))
                    .Returns(null);
            }
            var finalTogle = A.Fake<Fake<IFeatureToggle>>();
            finalTogle.CallsTo(ft => ft.IsEnabled(feature))
                .Returns(true);
            featureToggles.Add(finalTogle);

            A.CallTo(() => toggleProvider.GetFeatureToggles())
                .Returns(featureToggles.Select(f => f.FakedObject));

            sut.IsEnabled(feature);

            foreach (Fake<IFeatureToggle> fake in featureToggles)
            {
                fake.CallsTo(ft => ft.IsEnabled(feature))
                    .MustHaveHappened();
            }
        }
开发者ID:johnduhart,项目名称:toggled,代码行数:25,代码来源:FeatureContextTests.cs

示例10: GetPatientProcedures

        public IEnumerable<PatientProcedure> GetPatientProcedures(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientProcedures)
        {
            fixture.Customize<PatientProcedure>(pp => pp.With(x => x.PatientId, demographic.PatientId)
                                                        .Without(x => x.CptHcpcs));

            var procedures = fixture.CreateMany<PatientProcedure>(randomizer.Next(0, maxNumberOfPatientProcedures + 1)).ToList();
            foreach (var procedure in procedures)
            {
                procedure.ProcedureDate = procedure.ProcedureDate.Date;

                var hasFavoredProcedure = randomizer.NextPercent() <= ChanceOfHavingFavoredProcedure;
                procedure.CptHcpcs = hasFavoredProcedure ? randomizer.NextListElement(_favoredProcedureCodes) : GetRandomProcedure(randomizer);

                var isProcedureRecent = randomizer.NextPercent() <= ChanceOfHavingRecentProcedure;
                if(isProcedureRecent)
                {
                    var oldestRecentDateTime = DateTime.Today.AddMonths(-6);
                    if(procedure.ProcedureDate < oldestRecentDateTime)
                    {
                        var maximumNumberOfDaysForRecent = (int)(DateTime.Today - oldestRecentDateTime).TotalDays;
                        var daysAgo = randomizer.Next(1, maximumNumberOfDaysForRecent);
                        procedure.ProcedureDate = DateTime.Today.AddDays(-daysAgo);
                    }
                }
            }

            return procedures.OrderBy(x => x.ProcedureDate);
        }
开发者ID:ryanpeelman,项目名称:EMRG,代码行数:28,代码来源:PatientProcedureBuilder.cs

示例11: Create

				public static TestData Create(int projectCount=5)
				{
					var fixture = new Fixture();
					var returnValue = new TestData
					{
						Fixture = fixture,
						UserName = fixture.Create<string>("UserName"),
						ProjectList = fixture.CreateMany<DeployProject>(projectCount).ToList(),
						ProjectRoleManager = new Mock<IProjectRoleManager>(),
                        SystemRoleManager = new Mock<ISystemRoleManager>(),
						UserIdentity = new Mock<IUserIdentity>()
					};
					returnValue.DeployProjectRoleList = 
						(from i in returnValue.ProjectList
						 select new DeployProjectRole
							{
								ProjectId = i.Id,
								RoleName = fixture.Create<string>("RoleName")
							}
						).ToList();
                    returnValue.ProjectRoleManager.Setup(i => i.GetProjectRoleListForUser(It.IsAny<string>())).Returns(new List<DeployProjectRole>());
                    returnValue.ProjectRoleManager.Setup(i => i.GetProjectRoleListForUser(returnValue.UserName)).Returns(returnValue.DeployProjectRoleList);

                    returnValue.SystemRoleManager.Setup(i=>i.GetSystemRoleListForUser(It.IsAny<string>())).Returns(new List<SystemRole>());

					returnValue.UserIdentity.Setup(i=>i.UserName).Returns(returnValue.UserName);

					returnValue.Sut = new PermissionValidator(returnValue.ProjectRoleManager.Object, returnValue.SystemRoleManager.Object, returnValue.UserIdentity.Object);

					return returnValue;
				}
开发者ID:gsbastian,项目名称:Sriracha.Deploy,代码行数:31,代码来源:PermissionValidatorTests.cs

示例12: Main

        private static void Main(string[] args)
        {
            var fixture = new Fixture();
            fixture.Customizations.Add(new FirstNameBuilder());
            fixture.Customizations.Add(new AddressListBuilder());

            var aNumber = fixture.Create<int>();
            Console.WriteLine("Autofixture initialised aNumber with {0}\n\n\n", aNumber);

            var aString = fixture.Create<string>();
            Console.WriteLine("Autofixture initialised aString with {0}\n\n\n", aString);

            var aPerson = fixture.Create<Person>();
            Console.WriteLine("Autofixture initialised aContact with...\n\n {0}", aPerson);

            const int contactCount = 3;
            var people = fixture.CreateMany<Person>(contactCount);

            Console.WriteLine("Autofixture initialised {0} contacts...\n\n", contactCount);

            foreach (var person in people)
            {
                Console.WriteLine("\n\n{0}", person);
            }

            Console.ReadKey();
        }
开发者ID:GuyHarwood,项目名称:AutoFixtureDemo,代码行数:27,代码来源:Program.cs

示例13: TestInitialize

 public void TestInitialize()
 {
     var fixture = new Fixture();
     factories = Substitute.For<Factories>();
     navigator = Substitute.For<Navigator>();
     stateProvider = Substitute.For<StateProvider>();
     facade = Substitute.For<ReplacementBuilderAndSugarEstimatorFacade>();
     clipboard = Substitute.For<Clipboard>();
     messageDialog = Substitute.For<MessageDialog>();
     navigation = new InsulinEditingViewModel.Navigation();
     CreateSut();
     insulin = fixture.Create<Insulin>();
     insulin.InitializeCircumstances(new List<Guid>());
     insulin.SetOwner(factories);
     sugar = new Sugar();
     sugar.SetOwner(factories);
     factories.InsulinCircumstances.Returns(fixture.CreateMany<InsulinCircumstance>().ToList());
     factories.CreateSugar().Returns(sugar);
     settings = new Settings { MaxBolus = 5 };
     factories.Settings.Returns(settings);
     meal = fixture.Create<Meal>();
     factories.Finder.FindMealByInsulin(insulin).Returns(meal);
     factories.Finder.FindInsulinById(insulin.Id).Returns(insulin);
     var replacementAndEstimatedSugars = new ReplacementAndEstimatedSugars();
     replacementAndEstimatedSugars.EstimatedSugars = new List<Sugar>();
     replacementAndEstimatedSugars.Replacement
         = new Replacement { InsulinTotal = new Insulin(), Items = new List<ReplacementItem>() };
     facade.GetReplacementAndEstimatedSugars(Arg.Any<Meal>(), Arg.Any<Insulin>(), Arg.Any<Sugar>())
             .Returns(replacementAndEstimatedSugars);
     factories.MealNames.Returns(new List<MealName>());
     stateProvider.State.Returns(new Dictionary<string, object>());
 }
开发者ID:PawelStroinski,项目名称:Diettr-GPL,代码行数:32,代码来源:InsulinEditingViewModelTests.cs

示例14: TestInitialize

		public void TestInitialize()
		{
			_fixture = new Fixture();
			_awbRepository = new Mock<IAwbRepository>(MockBehavior.Strict);
			_awbIds = Enumerable.Range(0, AWBCount).Select(x => (long)x).ToArray();
			_awbsData = _awbIds.Select(i => _fixture.Build<AirWaybillData>()
				.With(d => d.Id, i)
				.Create()).ToArray();
			_awbRepository.Setup(x => x.Get(_awbIds)).Returns(_awbsData);

			_applications = _fixture.CreateMany<ApplicationListItem>(AppCount).ToArray();
			for(var i = 0; i < AppCount; i++)
			{
				var item = _applications[i];
				item.AirWaybillId = i % AWBCount;
				item.Id = i;
				item.ClientNic = "Client " + i % ClientCount;
				item.Count = i;
				item.Weight = i;
				item.Value = i;
				item.Volume = i;
			}

			_grouper = new ApplicationGrouper(_awbRepository.Object);
		}
开发者ID:UHgEHEP,项目名称:test,代码行数:25,代码来源:ApplicationGrouperTests.cs

示例15: Given_WhenWhen_ShouldExpectedResult

        public void Given_WhenWhen_ShouldExpectedResult()
        {
            var documentStore = new DocumentStore { Url = "http://mamluka-pc:4253" };
            documentStore.Initialize();

            var fixture = new Fixture();

            using (var session = documentStore.OpenSession())
            {
                var theList = fixture.CreateMany<Contact>(1000).ToList();

                theList.Take(500).ToList().ForEach(x => x.DomainGroup = "a");
                theList.Skip(500).Take(500).ToList().ForEach(x => x.DomainGroup = "b");

                var bigDoc = new Holder
                                 {
                                     TheList = theList
                                 };

                session.Store(bigDoc);
                session.SaveChanges();
            }

            documentStore.DatabaseCommands.PutIndex("Count_Contacts", new IndexDefinitionBuilder<Holder, SummeryOfDomains>
            {
                Map = contacts => contacts.SelectMany(x => x.TheList).Select(x => new { x.DomainGroup, Count = 1 }),
                Reduce = results => results.GroupBy(x => x.DomainGroup).Select(x => new { DomainGroup = x.Key, Count = x.Sum(m => m.Count) })

            }, true);

            using (var session = documentStore.OpenSession())
            {
                Trace.WriteLine(session.Query<List<int>>("Count_Contacts").First());
            }
        }
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:35,代码来源:RavenSizesTest.cs


注:本文中的Fixture.CreateMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。