Here are the examples of the csharp api Xunit.Assert.IsType(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
652 Examples
19
Source : ImageTests.cs
with MIT License
from haven1433
with MIT License
from haven1433
[Fact]
public void UncompressedPalette_DeleteColor_BecomesBlack() {
SetFullModel(0b01010101);
Model.ObserveRunWritten(new NoDataChangeDeltaModel(), new PaletteRun(0, new PaletteFormat(4, 1)));
ViewPort.Refresh();
ViewPort.SelectionStart = ViewPort.ConvertAddressToViewPoint(2);
ViewPort.SelectionEnd = ViewPort.ConvertAddressToViewPoint(3);
ViewPort.Clear.Execute();
replacedert.Equal(0, Model.ReadMultiByteValue(2, 2));
replacedert.IsType<PaletteRun>(Model.GetNextRun(0));
}
19
Source : ThumbRepointTests.cs
with MIT License
from haven1433
with MIT License
from haven1433
[Theory]
[InlineData(0)]
[InlineData(1)]
public void RepointThumb_ValidSelection_Repoints(int register) {
Parser.Compile(Token, Model, 0, $"mov r{register}, #0", "nop", "nop", "nop");
SelectRange(0, 8);
Tool.RepointThumb();
var expectedCode = Parser.Compile(Model, 0,
$"ldr r{register}, [pc, <000004>]",
$"bx r{register}",
"000004: .word <101>"); // destination + 1
replacedert.All(Enumerable.Range(0, expectedCode.Count), i => replacedert.Equal(expectedCode[i], Model[i]));
expectedCode = Parser.Compile(Model, 0x100,
$"ldr r{register}, [pc, <110>]",
$"mov lr, r{register}",
$"mov r{register}, #0",
"nop", "nop", "nop",
"bx lr",
"110: .word <9>"); // destination + 1
replacedert.All(Enumerable.Range(0, expectedCode.Count), i => replacedert.Equal(expectedCode[i], Model[0x100 + i]));
replacedert.Single(Messages);
replacedert.Equal(0x100, ViewPort.DataOffset);
replacedert.Equal(0x100, ToAddress(ViewPort.SelectionStart));
replacedert.Equal(0x113, ToAddress(ViewPort.SelectionEnd));
replacedert.IsType<PointerRun>(Model.GetNextRun(0x110));
}
19
Source : TupleTests.cs
with MIT License
from haven1433
with MIT License
from haven1433
[Fact]
public void TableFormat_TupleSpecified_CreatesTuple() {
ViewPort.Edit("^table[value:|t]1 ");
replacedert.IsType<ArrayRunTupleSegment>(Model.GetTable("table").ElementContent[0]);
}
19
Source : ViewPortEditTests.cs
with MIT License
from haven1433
with MIT License
from haven1433
[Fact]
public void SingleCharacterEditChangesToUnderEditFormat() {
ViewPort.SelectionStart = new Point(0, 2);
ViewPort.Edit("F");
replacedert.IsType<UnderEdit>(ViewPort[0, 2].Format);
replacedert.Equal("F", ((UnderEdit)ViewPort[0, 2].Format).CurrentText);
}
19
Source : ViewPortEditTests.cs
with MIT License
from haven1433
with MIT License
from haven1433
[Fact]
public void UnsupportedCharacterRevertsChangeWithoutAddingUndoOperation() {
ViewPort.SelectionStart = new Point(0, 2);
ViewPort.Edit("F");
ViewPort.Edit("|");
replacedert.IsType<None>(ViewPort[0, 2].Format);
replacedert.Equal(new Point(0, 2), ViewPort.SelectionStart);
replacedert.Equal(0, ViewPort[0, 2].Value);
replacedert.False(ViewPort.Undo.CanExecute(null));
}
19
Source : LayoutServiceTest.cs
with MIT License
from Invvard
with MIT License
from Invvard
[ Theory ]
[ InlineData("EOEb", "ergodox-ez", "ergodox-ez", true) ]
[ InlineData("EOEb", "planck-ez", "ergodox-ez", true) ]
[ InlineData("default", "ergodox-ez", "ergodox-ez", true) ]
[ InlineData("default", "moonlander", "moonlander", true) ]
[ InlineData("test", "ergodox-ez", "ergodox-ez", false) ]
public async Task GetLayoutInfo(string layoutHashId, string geometry, string expectedGeometry, bool exist)
{
// Arrange
ILayoutService layoutService = new LayoutService();
ErgodoxLayout response = null;
// Act
if (exist)
{
response = await layoutService.GetLayoutInfo(layoutHashId, geometry, "latest");
}
else
{
await replacedert.ThrowsAsync<ArgumentException>(() => layoutService.GetLayoutInfo(layoutHashId, geometry, "latest"));
}
// replacedert
if (exist)
{
replacedert.NotNull(response);
replacedert.IsType<ErgodoxLayout>(response);
replacedert.NotNull(response.Revision);
replacedert.False(string.IsNullOrWhiteSpace(response.HashId));
replacedert.False(string.IsNullOrWhiteSpace(response.replacedle));
replacedert.Equal(expectedGeometry, response.Geometry);
}
}
19
Source : LayoutServiceTest.cs
with MIT License
from Invvard
with MIT License
from Invvard
[ Theory ]
[ InlineData("EOEb", true) ]
[ InlineData("default", true) ]
[ InlineData("test", false) ]
public async Task GetErgodoxLayout(string layoutHashId, bool exist)
{
// Arrange
ILayoutService layoutService = new LayoutService();
// Act
ErgodoxLayout response = null;
if (exist)
{
response = await layoutService.GetErgodoxLayout(layoutHashId, "ergodox-ez", "latest");
}
else
{
await replacedert.ThrowsAsync<ArgumentException>(() => layoutService.GetErgodoxLayout(layoutHashId, "ergodox-ez", "latest"));
}
// replacedert
if (exist)
{
replacedert.NotNull(response);
replacedert.IsType<ErgodoxLayout>(response);
replacedert.NotNull(response.Revision);
replacedert.False(string.IsNullOrWhiteSpace(response.HashId));
replacedert.False(string.IsNullOrWhiteSpace(response.replacedle));
}
}
19
Source : PurchaseServiceTests.cs
with MIT License
from jonathanpeppers
with MIT License
from jonathanpeppers
[Fact]
public async Task GetSinglePrice()
{
var purchases = await _purchaseService.GetPrices(Purchase1);
replacedert.Equal(1, purchases.Length);
var purchase = purchases[0];
replacedert.Equal(Purchase1, purchase.Id);
replacedert.IsType<SKProduct>(purchase.NativeObject);
replacedert.Equal("$0.99", purchase.Price); //NOTE: test will fail if not in U.S.
}
19
Source : PurchaseServiceTests.cs
with MIT License
from jonathanpeppers
with MIT License
from jonathanpeppers
[Fact]
public async Task GetTwoPrices()
{
var purchases = await _purchaseService.GetPrices(Purchase1, Purchase2);
replacedert.Equal(2, purchases.Length);
var purchase = purchases[0];
replacedert.Equal(Purchase1, purchase.Id);
replacedert.IsType<SKProduct>(purchase.NativeObject);
replacedert.Equal("$0.99", purchase.Price); //NOTE: test will fail if not in U.S.
purchase = purchases[1];
replacedert.Equal(Purchase2, purchase.Id);
replacedert.IsType<SKProduct>(purchase.NativeObject);
replacedert.Equal("$1.99", purchase.Price); //NOTE: test will fail if not in U.S.
}
19
Source : ReopenDocumentCommandFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShouldCreate_ReopenDoreplacedentCommand()
{
var factory = new ReopenDoreplacedentCommandFactory(null);
var command = factory.CreateCommand(NullDoreplacedent.Instance);
replacedert.IsType<ReopenDoreplacedentCommand>(command);
}
19
Source : DoNothingDocumentCommandFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShouldCreate_DoNothingCommand()
{
var factory = new DoNothingDoreplacedentCommandFactory();
var command = factory.CreateCommand(NullDoreplacedent.Instance);
replacedert.IsType<DoNothingCommand>(command);
}
19
Source : HistoryCommandFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Handle_Null()
{
var factory = new HistoryCommandFactory<FakeCommand>(null, null);
var command = factory.CreateCommand();
replacedert.NotNull(command);
replacedert.IsType<FakeCommand>(command);
}
19
Source : HistoryCommandFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Create_Command()
{
var factory = new HistoryCommandFactory<FakeCommand2>(_doreplacedentHistoryCommandsMock.Object, _doreplacedentCommandFactoryMock.Object);
var command = factory.CreateCommand();
replacedert.NotNull(command);
replacedert.IsType<FakeCommand2>(command);
replacedert.Equal((command as FakeCommand2).DoreplacedentHistoryCommands, _doreplacedentHistoryCommandsMock.Object);
replacedert.Equal((command as FakeCommand2).DoreplacedentCommandFactory, _doreplacedentCommandFactoryMock.Object);
}
19
Source : HistoryCommandFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Create_Command_With_Doreplacedents()
{
var factory = new HistoryCommandFactory<FakeCommand2>(_doreplacedentHistoryCommandsMock.Object, _doreplacedentCommandFactoryMock.Object);
var docs = new IClosedDoreplacedent[]
{
NullDoreplacedent.Instance
};
var command = factory.CreateCommand(docs);
replacedert.NotNull(command);
replacedert.IsType<FakeCommand2>(command);
replacedert.Equal((command as FakeCommand2).ClosedDoreplacedents, docs);
}
19
Source : LoggerContextTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Have_Default_Context()
{
replacedert.NotNull(LoggerContext.Current);
replacedert.IsType<DefaultLoggerContext>(LoggerContext.Current);
}
19
Source : LoggerContextTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Not_Allow_To_Set_Context_To_Null()
{
LoggerContext.Current = null;
replacedert.NotNull(LoggerContext.Current);
replacedert.IsType<DefaultLoggerContext>(LoggerContext.Current);
}
19
Source : VsDteVersionContextTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Encapsulate_VsDteVersionProvider()
{
var provider = _vsDteVersionContext.VersionProvider;
replacedert.IsType<VsDteVersionProvider>(provider);
}
19
Source : JsonHistoryRepositoryFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Handle_ValidObject()
{
_configContext.Configuration.SetupGet(g => g.VSTempFolderName).Returns("VSTempFolderName");
_configContext.Configuration.SetupGet(g => g.PackageWorkingDirName).Returns("PackageWorkingDirName");
_configContext.Configuration.SetupGet(g => g.HistoryFileName).Returns("HistoryFileName");
var ret = _jsonHistoryRepositoryFactory.CreateHistoryRepository(new SolutionInfo("c:\\", "test"));
replacedert.NotNull(ret);
replacedert.IsType<JsonHistoryRepository>(ret);
}
19
Source : JsonIHistoryToolWindowRepositoryFactoryTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[Fact]
public void ItShould_Handle_ValidObject()
{
_configContext.Configuration.SetupGet(g => g.PackageWorkingDirName).Returns("PackageWorkingDirName");
_configContext.Configuration.SetupGet(g => g.ToolWindowSettingsFileName).Returns("ToolWindowSettingsFileName");
var ret = _jsonHistoryRepositoryFactory.Create();
replacedert.NotNull(ret);
replacedert.IsType<JsonHistoryToolWindowRepository>(ret);
}
19
Source : ButtonDisabledStateTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[StaFact]
public void ButtonDisabledState_Should_Disable_No_State_Change()
{
_imageButtonState.Disable();
var button = GetButton(_imageButtonState);
var state = button.GetImageButtonState();
replacedert.False(button.IsEnabled);
replacedert.Same(_disableImage, button.Content);
replacedert.IsType<ButtonDisabledState>(state);
}
19
Source : ButtonDisabledStateTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[StaFact]
public void ButtonDisabledState_Should_Enable_And_Change_State()
{
_imageButtonState.Enable();
var button = GetButton(_imageButtonState);
var state = button.GetImageButtonState();
replacedert.True(button.IsEnabled);
replacedert.Same(_enableImage, button.Content);
replacedert.IsType<ButtonEnabledState>(state);
}
19
Source : ButtonEnabledStateTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[StaFact]
public void ButtonEnabledState_Should_Disable_And_Change_State()
{
_imageButtonState.Disable();
var button = GetButton(_imageButtonState);
var state = button.GetImageButtonState();
replacedert.False(button.IsEnabled);
replacedert.Same(_disableImage, button.Content);
replacedert.IsType<ButtonDisabledState>(state);
}
19
Source : ButtonEnabledStateTest.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
[StaFact]
public void ButtonEnabledState_Should_Enable_No_State_Change()
{
_imageButtonState.Enable();
var button = GetButton(_imageButtonState);
var state = button.GetImageButtonState();
replacedert.True(button.IsEnabled);
replacedert.Same(_enableImage, button.Content);
replacedert.IsType<ButtonEnabledState>(state);
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
public void MoveFileSourceDoesNotExistThrowsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / @"parent1\src";
var destination = testDirectory.Path / @"parent2\dst";
FileSystem.CreateDirectory(source.Parent);
Action a = () => FileSystem.MoveFile(source, destination, false);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<FileNotFoundException>(exception);
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
public void MoveFileDestinationDirectoryDoesNotExistThrowsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / @"parent1\src";
var destination = testDirectory.Path / @"parent2\dst";
FileSystem.CreateDirectory(source.Parent);
FileSystem.WriteAllBytes(source, new byte[] { 1, 2, 3 });
Action a = () => FileSystem.MoveFile(source, destination, false);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<DirectoryNotFoundException>(exception);
replacedert.True(exception.Message.Contains("The system cannot find the path specified.") || exception.Message.Contains("Could not find a part of the path"), exception.Message);
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
public void MoveFileDestinationAlreadyExistsThrowsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / @"parent1\src";
var destination = testDirectory.Path / @"parent2\dst";
FileSystem.CreateDirectory(source.Parent);
FileSystem.CreateDirectory(destination.Parent);
FileSystem.WriteAllBytes(source, new byte[] { 1, 2, 3 });
var destinationBytes = new byte[] { 4, 5, 6 };
FileSystem.WriteAllBytes(destination, destinationBytes);
Action a = () => FileSystem.MoveFile(source, destination, false);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<IOException>(exception);
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
[Trait("Category", "WindowsOSOnly")] // ShareRead does not block Delete or Move in coreclr
public void MoveFileDestinationIsOpenedOverwriteThrowsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / "parent1" / "src";
var destination = testDirectory.Path / @"parent2" / "dst";
FileSystem.CreateDirectory(source.Parent);
FileSystem.CreateDirectory(destination.Parent);
FileSystem.WriteAllBytes(source, new byte[] { 1, 2, 3 });
var destinationBytes = new byte[] { 4, 5, 6 };
FileSystem.WriteAllBytes(destination, destinationBytes);
using (FileSystem.TryOpen(destination, FileAccess.Read, FileMode.Open, ShareRead))
{
Action a = () => FileSystem.MoveFile(source, destination, true);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<UnauthorizedAccessException>(exception);
replacedert.Contains("Access is denied.", exception.Message, StringComparison.OrdinalIgnoreCase);
}
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact(Skip = "TODO: Failing locally during conversion")]
[Trait("Category", "QTestSkip")] // Skipped
public void ReaderBlocksDeleteWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / @"src";
FileSystem.WriteAllBytes(source, new byte[] { 1 });
using (FileSystem.TryOpen(source, FileAccess.Read, FileMode.Open, ShareRead))
{
Action a = () => FileSystem.DeleteFile(source);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<UnauthorizedAccessException>(exception);
replacedert.Contains(
"The process cannot access the file because it is being used by another process.",
exception.Message,
StringComparison.OrdinalIgnoreCase);
}
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact(Skip = "TODO: Failing locally during conversion")]
[Trait("Category", "QTestSkip")] // Skipped
public void WriterBlocksDeleteWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var source = testDirectory.Path / @"src";
using (FileSystem.TryOpen(source, FileAccess.Write, FileMode.CreateNew, FileShare.None))
{
Action a = () => FileSystem.DeleteFile(source);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<UnauthorizedAccessException>(exception);
replacedert.Contains(
"The process cannot access the file because it is being used by another process.",
exception.Message,
StringComparison.OrdinalIgnoreCase);
}
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact(Skip = "TODO: Failing locally during conversion")]
[Trait("Category", "QTestSkip")] // Skipped
public void DeleteOneLinkWhileOtherLinkIsOpenReadOnlySharingFailsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var sourcePath = testDirectory.Path / @"source.txt";
var destinationPath = testDirectory.Path / @"destination.txt";
FileSystem.WriteAllBytes(sourcePath, ThreadSafeRandom.GetBytes(10));
replacedert.Equal(CreateHardLinkResult.Success, FileSystem.CreateHardLink(sourcePath, destinationPath, true));
using (FileSystem.TryOpen(sourcePath, FileAccess.Read, FileMode.Open, ShareRead))
{
Action a = () => FileSystem.DeleteFile(destinationPath);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<UnauthorizedAccessException>(exception);
replacedert.Contains(
"The process cannot access the file because it is being used by another process.",
exception.Message,
StringComparison.OrdinalIgnoreCase);
}
}
}
19
Source : PassThroughFileSystemTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact(Skip = "TODO: Failing locally during conversion")]
[Trait("Category", "QTestSkip")] // Skipped
public void DeleteOneLinkWhileOneOtherLinkIsOpenReadOnlySharingFailsWithAppropriateError()
{
using (var testDirectory = new DisposableDirectory(FileSystem))
{
var sourcePath = testDirectory.Path / @"source.txt";
var destinationPath1 = testDirectory.Path / @"destination1.txt";
var destinationPath2 = testDirectory.Path / @"destination2.txt";
FileSystem.WriteAllBytes(sourcePath, ThreadSafeRandom.GetBytes(10));
replacedert.Equal(CreateHardLinkResult.Success, FileSystem.CreateHardLink(sourcePath, destinationPath1, true));
replacedert.Equal(CreateHardLinkResult.Success, FileSystem.CreateHardLink(sourcePath, destinationPath2, true));
using (FileSystem.TryOpen(sourcePath, FileAccess.Read, FileMode.Open, ShareReadDelete))
using (FileSystem.TryOpen(destinationPath2, FileAccess.Read, FileMode.Open, ShareRead))
{
Action a = () => FileSystem.DeleteFile(destinationPath1);
var exception = Record.Exception(a);
replacedert.NotNull(exception);
replacedert.IsType<UnauthorizedAccessException>(exception);
replacedert.Contains(
"The process cannot access the file because it is being used by another process.",
exception.Message,
StringComparison.OrdinalIgnoreCase);
}
}
}
19
Source : AmbientTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[FactIfSupported(requiresWindowsBasedOperatingSystem: true)]
public void TestAmbientContextUses()
{
const string Config = @"
config({
mounts: [
{
name: a`NuGetCache`,
path: p`D:/NuGetCache`,
trackSourceFileChanges: true,
isWritable: false,
isReadable: true
},
],
});";
const string Spec = @"
// Any change will break Office.
const outDir = Context.getNewOutputDirectory(""testOut"");
const tempDir = Context.getTempDirectory(""testTemp"");
const hasMount = Context.hasMount(""NuGetCache"");
const mountPath = Context.getMount(""NuGetCache"").path;
const name = Context.getLastActiveUseName();
const moduleName = Context.getLastActiveUseModuleName();
const userHomeDir = Context.getUserHomeDirectory();
";
var results = Build()
.LegacyConfiguration(Config)
.Spec(Spec)
.EvaluateExpressionsWithNoErrors(
"outDir",
"tempDir",
"hasMount",
"mountPath",
"name",
"moduleName",
"userHomeDir");
replacedert.IsType<DirectoryArtifact>(results["outDir"]);
replacedert.IsType<DirectoryArtifact>(results["tempDir"]);
replacedert.True((bool) results["hasMount"]);
replacedert.Equal(CreateAbsolutePath(@"D:\NuGetCache"), results["mountPath"]);
replacedert.Equal("name", (string)results["name"]);
replacedert.Equal("__Config__", (string)results["moduleName"]); // This test evaluates in the main config context for simplicity so that is why this returns a 'funny' module name.
replacedert.IsType<DirectoryArtifact>(results["userHomeDir"]);
}
19
Source : AmbientTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[FactIfSupported(requiresWindowsBasedOperatingSystem: true)]
public void TestAmbientDirectoryUses()
{
const string Spec = @"
// Any change will break Office.
const dir = d`D:/path/to/a/directory`;
const dirPath = dir.path;
";
var results = EvaluateExpressionsWithNoErrors(Spec, "dir", "dirPath");
replacedert.IsType<DirectoryArtifact>(results["dir"]);
replacedert.Equal(CreateAbsolutePath(@"D:\path\to\a\directory"), results["dirPath"]);
}
19
Source : AmbientTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[FactIfSupported(requiresWindowsBasedOperatingSystem: true)]
public void TestAmbientTransformerUses()
{
const string Spec = @"
import {Transformer} from 'Sdk.Transformers';
// Any change will break Office.
const tool: Transformer.ToolDefinition = {
exe: f`O:/path/to/tool.exe`,
runtimeDependencies: [f`O:/path/to/tool.exe.config`],
runtimeDirectoryDependencies: [Transformer.sealDirectory(d`O:/path/to/aux`, [f`O:/path/to/aux/dep.in`])],
prepareTempDirectory: true,
dependsOnWindowsDirectories: true,
untrackedDirectoryScopes: [d`O:/dir/to/untracked`]
};
const sealedDir = Transformer.sealDirectory(d`O:/dir/subdirA`, [f`O:/dir/subdirA/1.txt`, f`O:/dir/subdirA/2.txt`]);
const sealedSourceDir = Transformer.sealSourceDirectory(d`O:/src/dev`, Transformer.SealSourceDirectoryOption.allDirectories);
const partiallySealedDir = Transformer.sealPartialDirectory(d`O:/dir/subdirB`, [f`O:/dir/subdirB/1.txt`, f`O:/dir/subdirB/2.txt`]);
const writtenFile = Transformer.writeFile(p`O:/out/dir/script.bat`, [""content1"", ""content2""]);
const execResult = Transformer.execute({
tool: tool,
description: ""O:/a/b/c/nmake_rule(10, 20)"",
tags: [""platform:x64|configuration:debug"", ""noculture""],
arguments: [{ name: undefined, value: ""start"" }],
workingDirectory: d`.`,
dependencies: [
f`O:/src/file.txt`,
writtenFile,
sealedDir,
partiallySealedDir
],
implicitOutputs: [p`O:/out/dir/outputFile.txt`, d`O:/out/dir/outputDir`],
environmentVariables: [
{ name: ""NAME1"", value: f`O:/some/path` },
{ name: ""NAME2"", value: ""SomeValue"" }
],
additionalTempDirectories: [d`O:/temp/dir1`, d`O:/tmp/dir2`],
unsafe: {
untrackedScopes: [d`O:/dir/to/untracked2`],
allowPreservedOutputs: false
}
});
const outputFile = execResult.getOutputFile(p`O:/out/dir/outputFile.txt`);
const outputDir = execResult.getOutputDirectory(d`O:/out/dir/outputDir`);
";
var results = EvaluateExpressionsWithNoErrors(
Spec,
"sealedDir",
"sealedSourceDir",
"partiallySealedDir",
"writtenFile",
"execResult",
"outputFile",
"outputDir");
replacedert.IsType<StaticDirectory>(results["sealedDir"]);
replacedert.IsType<StaticDirectory>(results["sealedSourceDir"]);
replacedert.IsType<StaticDirectory>(results["partiallySealedDir"]);
replacedert.Equal(CreateAbsolutePath(@"O:\dir\subdirA"), ((StaticDirectory) results["sealedDir"]).Path);
replacedert.Equal(CreateAbsolutePath(@"O:\src\dev"), ((StaticDirectory) results["sealedSourceDir"]).Path);
replacedert.Equal(CreateAbsolutePath(@"O:\dir\subdirB"), ((StaticDirectory) results["partiallySealedDir"]).Path);
replacedert.IsType<FileArtifact>(results["writtenFile"]);
replacedert.Equal(CreateOutputFile(@"O:\out\dir\script.bat"), results["writtenFile"]);
replacedert.IsreplacedignableFrom<ObjectLiteral>(results["execResult"]);
replacedert.IsType<FileArtifact>(results["outputFile"]);
replacedert.Equal(CreateOutputFile(@"O:\out\dir\outputFile.txt"), results["outputFile"]);
replacedert.IsType<StaticDirectory>(results["outputDir"]);
replacedert.Equal(CreateAbsolutePath(@"O:\out\dir\outputDir"), ((StaticDirectory) results["outputDir"]).Path);
}
19
Source : AmbientTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
private static void CheckUnorderedArray<T>(object expected, object actual)
{
var expectedArray = expected as ArrayLiteral;
var actualArray = actual as ArrayLiteral;
replacedert.NotNull(expectedArray);
replacedert.NotNull(actualArray);
replacedert.Equal(expectedArray.Length, actualArray.Length);
var actualPaths = new HashSet<T>();
for (var i = 0; i < actualArray.Length; ++i)
{
replacedert.IsType<T>(actualArray[i].Value);
actualPaths.Add((T) actualArray[i].Value);
}
for (var i = 0; i < expectedArray.Length; ++i)
{
replacedert.IsType<T>(expectedArray[i].Value);
replacedert.Contains((T) expectedArray[i].Value, actualPaths);
}
}
19
Source : AmbientTestsRealFileSystem.cs
with MIT License
from microsoft
with MIT License
from microsoft
[FactIfSupported(requiresWindowsBasedOperatingSystem: true)]
public void TestAmbientFileUses()
{
FileSystem = new PreplacedThroughMutableFileSystem(PathTable);
RelativeSourceRoot = System.IO.Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
const string Spec = @"
// Any change will break Office.
const file = f`D:/path/to/a/file.txt`;
const filePath = file.path;
const fileContent = File.readAllText(f`file.txt`);
";
var results = Build()
.Spec(Spec)
.AddFile("file.txt", "Hello")
.EvaluateExpressionsWithNoErrors("file", "filePath", "fileContent");
replacedert.IsType<FileArtifact>(results["file"]);
replacedert.True(((FileArtifact) results["file"]).IsSourceFile);
replacedert.Equal(CreateAbsolutePath(@"D:\path\to\a\file.txt"), results["filePath"]);
replacedert.Equal("Hello", results["fileContent"]);
}
19
Source : Extension.cs
with MIT License
from microsoft
with MIT License
from microsoft
public static Exception ShouldThrow<T>(this Action action)
{
Exception exception = null;
try
{
action.Invoke();
replacedert.False(true, "Did not expect to execute this statement!");
}
catch (Exception e)
{
replacedert.IsType<T>(e);
exception = e;
}
return exception;
}
19
Source : PackageReferenceFactoryTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
public void Create_PackageReference()
{
var reference = Mock.Of<ISetupPackageReference>(x => x.GetId() == "a");
var actual = PackageReferenceFactory.Create(reference);
replacedert.IsType<PackageReference>(actual);
}
19
Source : PackageReferenceFactoryTests.cs
with MIT License
from microsoft
with MIT License
from microsoft
[Fact]
public void Create_FailedPackageReference()
{
var reference = new Mock<ISetupFailedPackageReference>();
reference.As<ISetupPackageReference>().Setup(x => x.GetId()).Returns("a");
var actual = PackageReferenceFactory.Create(reference.Object);
replacedert.IsType<FailedPackageReference>(actual);
}
19
Source : PanelViewTests.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void Add_More_Views_Remove_Last_Child_Before__Only_One_Is_Allowed ()
{
var pv = new PanelView (new Label ("This is a test."));
replacedert.NotNull (pv.Child);
replacedert.Equal (1, pv.Subviews [0].Subviews.Count);
replacedert.IsType<Label> (pv.Child);
pv.Add (new TextField ("This is a test."));
replacedert.NotNull (pv.Child);
replacedert.Equal (1, pv.Subviews [0].Subviews.Count);
replacedert.IsNotType<Label> (pv.Child);
replacedert.IsType<TextField> (pv.Child);
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void Version()
{
replacedert.NotNull(TFCore.Version);
replacedert.IsType<string>(TFCore.Version);
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void Variables()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
TFStatus status = new TFStatus();
var runner = s.GetRunner();
TFOutput vW, vb, vlinmodel;
var hW = g.Variable(g.Const(0.3F, TFDataType.Float), out vW);
var hb = g.Variable(g.Const(-0.3F, TFDataType.Float), out vb);
var hlinearmodel = g.Variable(g.Const(0.0F, TFDataType.Float), out vlinmodel);
var x = g.Placeholder(TFDataType.Float);
var hoplm = g.replacedignVariableOp(hlinearmodel, g.Add(g.Mul(vW, x), vb));
//init all variable
runner
.AddTarget(g.GetGlobalVariablesInitializer())
.AddTarget(hoplm)
.AddInput(x, new float[] { 1F, 2F, 3F, 4F })
.Run(status);
//now get actual value
var result = s.GetRunner()
.Fetch(vlinmodel)
.Run();
replacedert.NotNull(result);
replacedert.Equal(1, result.Length);
replacedert.IsType<float[]>(result[0].GetValue());
float[] values = (float[])result[0].GetValue();
replacedert.NotNull(values);
replacedert.Equal(4, values.Length);
replacedert.Equal(0.0F, values[0], 7);
replacedert.Equal(0.3F, values[1], 7);
replacedert.Equal(0.6F, values[2], 7);
replacedert.Equal(0.9F, values[3], 7);
}
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void BasicConstantOps()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
var a = g.Const(2);
replacedert.NotNull(a);
replacedert.Equal(TFDataType.Int32, a.OutputType);
var b = g.Const(3);
replacedert.NotNull(b);
replacedert.Equal(TFDataType.Int32, b.OutputType);
// Add two constants
var results = s.GetRunner().Run(g.Add(a, b));
replacedert.NotNull(results);
replacedert.IsType<TFTensor>(results);
replacedert.Equal(TFDataType.Int32, results.TensorType);
replacedert.Equal(0, results.NumDims);
replacedert.Equal(0, results.Shape.Length);
var val = results.GetValue();
replacedert.NotNull(val);
replacedert.Equal(5, val);
// Multiply two constants
results = s.GetRunner().Run(g.Mul(a, b));
replacedert.NotNull(results);
replacedert.IsType<TFTensor>(results);
replacedert.Equal(TFDataType.Int32, results.TensorType);
replacedert.Equal(0, results.NumDims);
replacedert.Equal(0, results.Shape.Length);
replacedert.NotNull(results.GetValue());
replacedert.Equal(6, results.GetValue());
}
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void BasicConstantZerosAndOnes()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
// Test Zeros, Ones for n x n shape
var o = g.Ones(new TFShape(4, 4));
replacedert.NotNull(o);
replacedert.Equal(TFDataType.Double, o.OutputType);
var z = g.Zeros(new TFShape(4, 4));
replacedert.NotNull(z);
replacedert.Equal(TFDataType.Double, z.OutputType);
var r = g.RandomNormal(new TFShape(4, 4));
replacedert.NotNull(r);
replacedert.Equal(TFDataType.Double, r.OutputType);
var res1 = s.GetRunner().Run(g.Mul(o, r));
replacedert.NotNull(res1);
replacedert.Equal(TFDataType.Double, res1.TensorType);
replacedert.Equal(2, res1.NumDims);
replacedert.Equal(4, res1.Shape[0]);
replacedert.Equal(4, res1.Shape[1]);
replacedert.Equal("[4x4]", res1.ToString());
var matval1 = res1.GetValue();
replacedert.NotNull(matval1);
replacedert.IsType<double[,]>(matval1);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
replacedert.NotNull(((double[,])matval1)[i, j]);
}
}
var res2 = s.GetRunner().Run(g.Mul(g.Mul(o, r), z));
replacedert.NotNull(res2);
replacedert.Equal(TFDataType.Double, res2.TensorType);
replacedert.Equal(2, res2.NumDims);
replacedert.Equal(4, res2.Shape[0]);
replacedert.Equal(4, res2.Shape[1]);
replacedert.Equal("[4x4]", res2.ToString());
var matval2 = res2.GetValue();
replacedert.NotNull(matval2);
replacedert.IsType<double[,]>(matval2);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
replacedert.NotNull(((double[,])matval2)[i, j]);
replacedert.Equal(0.0, ((double[,])matval2)[i, j]);
}
}
}
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void BasicConstantsOnSymmetricalShapes()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
//build some test vectors
var o = g.Ones(new TFShape(4, 4));
var z = g.Zeros(new TFShape(4, 4));
var r = g.RandomNormal(new TFShape(4, 4));
var matval = s.GetRunner().Run(g.Mul(o, r)).GetValue();
var matvalzero = s.GetRunner().Run(g.Mul(g.Mul(o, r), z)).GetValue();
var co = g.Constant(1.0, new TFShape(4, 4), TFDataType.Double);
var cz = g.Constant(0.0, new TFShape(4, 4), TFDataType.Double);
var res1 = s.GetRunner().Run(g.Mul(co, r));
replacedert.NotNull(res1);
replacedert.Equal(TFDataType.Double, res1.TensorType);
replacedert.Equal(2, res1.NumDims);
replacedert.Equal(4, res1.Shape[0]);
replacedert.Equal(4, res1.Shape[1]);
replacedert.Equal("[4x4]", res1.ToString());
var cmatval1 = res1.GetValue();
replacedert.NotNull(cmatval1);
replacedert.IsType<double[,]>(cmatval1);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
replacedert.NotNull(((double[,])cmatval1)[i, j]);
}
}
var cres2 = s.GetRunner().Run(g.Mul(g.Mul(co, r), cz));
replacedert.NotNull(cres2);
replacedert.Equal(TFDataType.Double, cres2.TensorType);
replacedert.Equal(2, cres2.NumDims);
replacedert.Equal(4, cres2.Shape[0]);
replacedert.Equal(4, cres2.Shape[1]);
replacedert.Equal("[4x4]", cres2.ToString());
var cmatval2 = cres2.GetValue();
replacedert.NotNull(cmatval2);
replacedert.IsType<double[,]>(cmatval2);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
replacedert.NotNull(((double[,])cmatval2)[i, j]);
replacedert.Equal(((double[,])matvalzero)[i, j], ((double[,])cmatval2)[i, j]);
}
}
}
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void BasicConstantsUnSymmetrical()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
var o = g.Ones(new TFShape(4, 3));
replacedert.NotNull(o);
replacedert.Equal(TFDataType.Double, o.OutputType);
var r = g.RandomNormal(new TFShape(3, 5));
replacedert.NotNull(o);
replacedert.Equal(TFDataType.Double, o.OutputType);
//expect incompatible shapes
replacedert.Throws<TFException>(() => s.GetRunner().Run(g.Mul(o, r)));
var res = s.GetRunner().Run(g.MatMul(o, r));
replacedert.NotNull(res);
replacedert.Equal(TFDataType.Double, res.TensorType);
replacedert.Equal(2, res.NumDims);
replacedert.Equal(4, res.Shape[0]);
replacedert.Equal(5, res.Shape[1]);
double[,] val = (double[,])res.GetValue();
replacedert.NotNull(val);
replacedert.IsType<double[,]>(val);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
replacedert.NotNull(((double[,])val)[i, j]);
}
}
}
}
19
Source : GettingStarted.cs
with MIT License
from migueldeicaza
with MIT License
from migueldeicaza
[Fact]
public void BasicMatrix()
{
using (TFGraph g = new TFGraph ())
using (TFSession s = new TFSession (g))
{
// 1x2 matrix
var matrix1 = g.Const(new double[,] { { 3, 3 } });
// 2x1 matrix
var matrix2 = g.Const(new double[,] { { 2 }, { 2 } });
var expected = new double[,] { { 12 } };
var res = s.GetRunner().Run(g.MatMul(matrix1, matrix2));
replacedert.NotNull(res);
replacedert.Equal(TFDataType.Double, res.TensorType);
replacedert.Equal(2, res.NumDims);
replacedert.Equal(1, res.Shape[0]);
replacedert.Equal(1, res.Shape[1]);
double[,] val = (double[,])res.GetValue();
replacedert.NotNull(val);
replacedert.IsType<double[,]>(val);
replacedert.Equal(expected[0,0], val[0, 0]);
}
}
19
Source : ProcessManagerFactoryTests.cs
with BSD 2-Clause "Simplified" License
from mysteryx93
with BSD 2-Clause "Simplified" License
from mysteryx93
[Fact]
public void Create_NoParam_ReturnsProcessManager()
{
var factory = SetupFactory();
var result = factory.Create(null);
replacedert.NotNull(result);
replacedert.IsType<ProcessWorker>(result);
replacedert.Same(_config, result.Config);
}
19
Source : ProcessManagerFactoryTests.cs
with BSD 2-Clause "Simplified" License
from mysteryx93
with BSD 2-Clause "Simplified" License
from mysteryx93
[Fact]
public void CreateEncoder_NoParam_ReturnsProcessManager()
{
var factory = SetupFactory();
var result = factory.CreateEncoder(null);
replacedert.NotNull(result);
replacedert.IsType<ProcessWorkerEncoder>(result);
replacedert.Same(_config, result.Config);
}
19
Source : TimeLeftCalculatorFactoryTests.cs
with BSD 2-Clause "Simplified" License
from mysteryx93
with BSD 2-Clause "Simplified" License
from mysteryx93
[Theory]
[InlineData(100)]
public void Create_1Param_ValidInstance(int frameCount)
{
var factory = SetupFactory();
var result = factory.Create(frameCount);
replacedert.NotNull(result);
replacedert.IsType<TimeLeftCalculator>(result);
replacedert.Equal(frameCount, result.FrameCount);
}
See More Examples