本文整理汇总了C#中Fixture.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Fixture.Create方法的具体用法?C# Fixture.Create怎么用?C# Fixture.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fixture
的用法示例。
在下文中一共展示了Fixture.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessAsync_ShouldCreateFile
public async Task ProcessAsync_ShouldCreateFile()
{
var fixture = new Fixture();
coinFile = fixture.Create<CoinFile>();
outboundVoucherFile = fixture.Create<OutboundVoucherFile>();
outboundVoucherFile.FileLocation = @"c:\someDir";
outboundVoucherFile.FileName = @"someFileName.xml";
mapper
.Setup(m => m.Map(It.IsAny<OutboundVoucherFile>()))
.Returns(coinFile);
coinFileWriter
.Setup(w => w.SaveFile(coinFile, @"c:\someDir\someFileName.xml"))
.Returns(() => Task.FromResult(string.Empty));
coinFileCreator = GetCoinFileCreator();
await coinFileCreator.ProcessAsync(outboundVoucherFile);
mapper.VerifyAll();
coinFileWriter.VerifyAll();
}
示例2: ZipDirectory_ReleasesLockOnZipFile
public void ZipDirectory_ReleasesLockOnZipFile()
{
var fixture = new Fixture();
string sourceDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(sourceDirectory);
string sourceFile1 = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".tmp");
File.WriteAllText(sourceFile1, fixture.Create<string>());
string sourceFile2 = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".tmp");
File.WriteAllText(sourceFile2, fixture.Create<string>());
string zipFilePath = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".zip");
try
{
var sut = new Zipper(new Mock<ILog>().Object);
sut.ZipDirectory(sourceDirectory, zipFilePath);
File.Delete(zipFilePath);
}
finally
{
try
{
Directory.Delete(sourceDirectory, true);
}
catch {}
try
{
File.Delete(zipFilePath);
}
catch { }
}
}
示例3: Create
public static TestData Create(int taskCount)
{
var fixture = new Fixture();
var returnValue = new TestData
{
TaskFactory = new Mock<IDeployTaskFactory>(),
StatusManager = new Mock<IDeployTaskStatusManager>(),
Component = fixture.Create<DeployComponent>(),
EnvironmentComponent = fixture.Create<DeployEnvironmentConfiguration>(),
Impersonator = new Mock<IImpersonator>(),
Build = fixture.Create<DeployBuild>(),
RuntimeSystemSettings = fixture.Create<RuntimeSystemSettings>(),
TaskDefinitionExecutorList = new TupleList<Mock<IDeployTaskDefinition>,Mock<IDeployTaskExecutor>,Type>(),
DeployStateId = fixture.Create<string>()
};
returnValue.EnvironmentComponent.DeployCredentialsId = null;
returnValue.Sut = new DeployComponentRunner(returnValue.TaskFactory.Object, returnValue.Impersonator.Object);
for (int index = 0; index < taskCount; index++)
{
var executorType = CreateType(fixture);
var taskDefinition = new Mock<IDeployTaskDefinition>();
var taskExecutor = new Mock<IDeployTaskExecutor>();
taskDefinition.Setup(i=>i.GetTaskExecutorType()).Returns(executorType);
returnValue.TaskFactory.Setup(i=>i.CreateTaskExecutor(executorType)).Returns(taskExecutor.Object);
returnValue.TaskDefinitionExecutorList.Add(taskDefinition, taskExecutor, executorType);
var successResult = new DeployTaskExecutionResult
{
Status = EnumDeployTaskExecutionResultStatus.Success
};
taskExecutor.Setup(i => i.Execute(returnValue.DeployStateId, returnValue.StatusManager.Object, taskDefinition.Object, returnValue.Component, returnValue.EnvironmentComponent, It.IsAny<DeployMachine>(), It.IsAny<DeployBuild>(), returnValue.RuntimeSystemSettings)).Returns(successResult);
}
return returnValue;
}
示例4: CanCreateXmlConfigTask
public void CanCreateXmlConfigTask()
{
var fixture = new Fixture();
string fieldName = fixture.Create<string>();
var task = new XmlConfigFileTaskDefinition(new ParameterParser())
{
Options = new XmlConfigFileTaskOptions
{
XmlTemplate = new StringBuilder()
.Append("<container>")
.Append("<environmentValue></environmentValue>")
.Append("</container>")
.ToString(),
TargetFileName = fixture.Create<string>(),
XPathValueList = new List<XmlConfigFileTaskOptions.XPathValueItem>
{
new XmlConfigFileTaskOptions.XPathValueItem
{
XPath = "/container/environmentValue",
ConfigLevel = EnumConfigLevel.Environment,
ValueName = fieldName
}
}
}
};
}
示例5: Create
public static TestData Create(bool existingUser = false)
{
var fixture = new Fixture();
var testData = new TestData
{
Fixture = fixture,
UserManager = new Mock<IUserManager>(),
SystemRoleManager = new Mock<ISystemRoleManager>(),
SystemSettings = new Mock<ISystemSettings>(),
AdministratorUserName = fixture.Create<string>("UserName"),
AdministratorPassword = fixture.Create<string>("Password"),
AdministratorEmailAddress = fixture.Create<string>("EmailAddress"),
AdministratorRole = fixture.Build<SystemRole>()
.With(i => i.RoleType, EnumSystemRoleType.Administrator)
.Create()
};
if (existingUser)
{
testData.ExistingUser = fixture.Build<SrirachaUser>()
.With(i => i.UserName, testData.AdministratorUserName)
.Create();
testData.UserManager.Setup(i => i.GetUser(testData.ExistingUser.Id)).Returns(testData.ExistingUser);
testData.UserManager.Setup(i => i.TryGetUserByUserName(testData.ExistingUser.UserName)).Returns(testData.ExistingUser);
testData.UserManager.Setup(i => i.GetUserByUserName(testData.ExistingUser.UserName)).Returns(testData.ExistingUser);
}
testData.SystemRoleManager.Setup(i => i.GetBuiltInRole(EnumSystemRoleType.Administrator)).Returns(testData.AdministratorRole);
testData.Sut = new SystemSetterUpper(testData.UserManager.Object, testData.SystemRoleManager.Object, testData.SystemSettings.Object);
return testData;
}
示例6: 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>());
}
示例7: 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;
}
示例8: 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();
}
示例9: GivenAMongoMessageDataRepository_WhenPuttingMessageDataWithExpiration
public void GivenAMongoMessageDataRepository_WhenPuttingMessageDataWithExpiration()
{
var db = new MongoClient().GetDatabase("messagedatastoretests");
_bucket = new GridFSBucket(db);
_now = DateTime.UtcNow;
SystemDateTime.Set(_now);
var fixture = new Fixture();
var resolver = new Mock<IMongoMessageUriResolver>();
resolver.Setup(x => x.Resolve(It.IsAny<ObjectId>()))
.Callback((ObjectId id) => _id = id);
var nameCreator = new Mock<IFileNameCreator>();
nameCreator.Setup(x => x.CreateFileName())
.Returns(fixture.Create<string>());
var sut = new MongoMessageDataRepository(resolver.Object, _bucket, nameCreator.Object);
_expectedTtl = TimeSpan.FromHours(1);
using (var stream = new MemoryStream(fixture.Create<byte[]>()))
{
sut.Put(stream, _expectedTtl).GetAwaiter().GetResult();
}
}
开发者ID:LiberisLabs,项目名称:MassTransit.MessageData.MongoDb,代码行数:26,代码来源:MongoMessageDataRepositoryTestsForPuttingMessageDataWithExpiration.cs
示例10: Setup
public void Setup()
{
_fixture = new Fixture();
_pmGateway = new Mock<IProjectManagerGateway>();
_projectRepository = new Mock<IProjectRepository>();
_vcsGateway = new Mock<IVersionControlSystemGateway>();
_eventSinkMock = new Mock<IEventSink>();
_userRepository = new Mock<IUserRepository>();
var paginationSettings = new ProjectManagement.Domain.PaginationSettings(10);
_pmGateway
.Setup(pm => pm.CreateProject(It.IsAny<CreateProjectRequest>()))
.Returns(_fixture.Create<RedmineProjectInfo>());
_vcsGateway
.Setup(vcs => vcs.CreateRepositoryForProject(It.IsAny<CreateProjectRequest>()))
.Returns(_fixture.Create<VersionControlSystemInfo>());
_projectRepository
.Setup(repo => repo.SaveProject(It.IsAny<Project>()))
.Returns(1);
_userRepository.Setup(repo => repo.GetUserRedmineId(It.IsAny<int>())).Returns(1);
_userRepository.Setup(repo => repo.GetUserGitlabId(It.IsAny<int>())).Returns(1);
_projectProvider = new ProjectProvider(
_pmGateway.Object,
_vcsGateway.Object,
_projectRepository.Object,
_eventSinkMock.Object,
_userRepository.Object,
paginationSettings,
new IssuePaginationSettings(25));
}
示例11: TestDeployDatabase
public void TestDeployDatabase()
{
var definition = new DeployRoundhouseDatabaseTaskDefinition(new ParameterParser());
definition.Options = new DeployRoundhouseDatabaseTaskOptions
{
EnvironmentName = "LOCAL",
DatabaseType = EnumRoundhouseDatabaseType.SqlServer,
SqlFilesDirectory = @"C:\Projects\Sriracha.Deploy\Repository\SqlServer\Sriracha.Deploy.SqlServer.RoundhousE\db",
ConnectionString = "Data Source=(local); Initial Catalog=TestRoundhouseTask; Integrated Security=SSPI;"
};
var executor = new DeployRoundhouseDatabaseExecutor(new ParameterEvaluator(new ParameterParser()), new DeploymentValidator(new DeployTaskFactory(new Mock<IDIFactory>().Object, new ModuleInspector())));
var fixture = new Fixture();
string deployStateId = fixture.Create<string>("DeployStateId");
var deployTaskStatusManager = new DeployTaskStatusManager(new Mock<ILog>().Object, new Mock<IDeployStateManager>().Object, new Mock<IDeployStatusNotifier>().Object);
var component = fixture.Create<DeployComponent>();
var environmentComponent = fixture.Create<DeployEnvironmentConfiguration>();
var machine = fixture.Create<DeployMachine>();
var build = fixture.Create<DeployBuild>();
var systemSettings = new RuntimeSystemSettings();
var result = executor.Execute(deployStateId, deployTaskStatusManager, definition, component, environmentComponent, machine, build, systemSettings);
Assert.IsNotNull(result);
Assert.AreEqual(EnumDeployTaskExecutionResultStatus.Success, result.Status);
}
示例12: ScannedPageFacadeTest
public ScannedPageFacadeTest()
{
_scannedPageMapper = new ScannedPageMapper();
_fixture = new Fixture();
_fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
_fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));
_fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel)));
_scannedPage = _fixture.Create<ScannedPage>();
_scannedPageBusinessModel = _fixture.Create<ScannedPageBusinessModel>();
_readerBusinessModel = _fixture.Create<ReaderBusinessModel>();
ReaderMapper readerMapper = new ReaderMapper();
_reader = readerMapper.Map(_readerBusinessModel);
_itemBusinessModel = _fixture.Create<ItemBusinessModel>();
ItemMapper itemMapper = new ItemMapper();
_item = itemMapper.Map(_itemBusinessModel);
this.uow = Initializer.GetLibraryUow();
uow.ScannedPages.Add(this._scannedPage);
uow.Readers.Add(this._reader);
uow.Items.Add(this._item);
this._scannedPageFacade = new ScannedPageFacade(uow);
}
示例13: TagScoreMapperTests
public TagScoreMapperTests()
{
this.mapper = new TagScoreMapper();
Fixture fixture = new Fixture{RepeatCount = 1};
fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));
Reader reader = fixture.Create<Reader>();
ReaderMapper readerMapper = new ReaderMapper();
var readerModel = readerMapper.Map(reader);
// item is book
Book book = fixture.Create<Book>();
this.entityWithBook = new TagScore{Id = 1, Item = book, Reader = reader, Score = 0.5f};
BookMapper bookMapper = new BookMapper();
var bookModel = bookMapper.Map(book);
this.modelWithBook = new TagScoreBusinessModel{Item = bookModel, Reader = readerModel, Score = 0.5f};
// item is disk
Disk disk = fixture.Create<Disk>();
this.entityWithDisk = new TagScore { Id = 1, Item = disk, Reader = reader, Score = 0.5f };
DiskMapper diskMapper = new DiskMapper();
var diskModel = diskMapper.Map(disk);
this.modelWithDisk = new TagScoreBusinessModel{Item = diskModel, Reader = readerModel, Score = 0.5f};
// item is magazine
Magazine magazine = fixture.Create<Magazine>();
this.entityWithMagazine = new TagScore { Id = 1, Item = magazine, Reader = reader, Score = 0.5f };
MagazineMapper magazineMapper = new MagazineMapper();
var magazineModel = magazineMapper.Map(magazine);
this.modelWithMagazine =
new TagScoreBusinessModel { Item = magazineModel, Reader = readerModel, Score = 0.5f };
}
示例14: SearchItemFacadeTest
public SearchItemFacadeTest()
{
_itemMapper = new ItemMapper();
_fixture = new Fixture();
_fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
_fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));
_fixture.Customizations.Add(new TypeRelay(typeof(ItemBusinessModel), typeof(BookBusinessModel)));
_readerBusinessModel = _fixture.Create<ReaderBusinessModel>();
ReaderMapper readerMapper = new ReaderMapper();
_reader = readerMapper.Map(_readerBusinessModel);
_item = _fixture.Create<Item>();
_itemBusinessModel = _itemMapper.Map(_item);
_tag = _fixture.Create<Tag>();
this.uow = Initializer.GetLibraryUow();
uow.Readers.Add(this._reader);
uow.Items.Add(this._item);
uow.Tags.Add(_tag);
this._searchItemFacade = new SearchItemFacade(uow);
}
示例15: Equals_DifferentMovies_ReturnsFalse
public void Equals_DifferentMovies_ReturnsFalse()
{
var fixture = new Fixture();
var id1 = fixture.Create<int>();
var dateUploadedUnix1 = fixture.Create<int>();
var id2 = fixture.Create<int>();
var dateUploadedUnix2 = fixture.Create<int>();
var movie1 = new MovieFull
{
Id = id1,
DateUploadedUnix = dateUploadedUnix1
};
var movie2 = new MovieFull
{
Id = id2,
DateUploadedUnix = dateUploadedUnix2
};
Assert.AreEqual(
_comparer.Equals(movie1, movie2), false);
Assert.AreEqual(
_comparer.Equals(movie1, null), false);
Assert.AreEqual(
_comparer.Equals(movie2, null), false);
}