本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Single方法的典型用法代码示例。如果您正苦于以下问题:C# List.Single方法的具体用法?C# List.Single怎么用?C# List.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhenPopulateMergedImageInfo_ThenPopulateVouchers
public void WhenPopulateMergedImageInfo_ThenPopulateVouchers()
{
var vouchers = new List<DipsNabChq>
{
new DipsNabChq {S_TRACE = "000000000001"},
new DipsNabChq {S_TRACE = "000000000002"},
};
ExpectDirectory(imageDirectory);
ExpectDirectory(targetDirectory);
ExpectImageFiles();
ExpectMergedImageFiles();
ExpectImageMetadataFile();
var sut = CreateHelper();
sut.PopulateMergedImageInfo(JobIdentifier, BatchNumber, vouchers);
var firstVoucher = vouchers.Single(x => x.S_TRACE == "000000000001");
Assert.AreEqual("0", firstVoucher.S_IMG1_OFF.Trim());
Assert.AreEqual("1", firstVoucher.S_IMG1_LEN.Trim());
Assert.AreEqual("0", firstVoucher.S_IMG2_OFF.Trim());
Assert.AreEqual("2", firstVoucher.S_IMG2_LEN.Trim());
var secondVoucher = vouchers.Single(x => x.S_TRACE == "000000000002");
Assert.AreEqual("1", secondVoucher.S_IMG1_OFF.Trim());
Assert.AreEqual("3", secondVoucher.S_IMG1_LEN.Trim());
Assert.AreEqual("2", secondVoucher.S_IMG2_OFF.Trim());
Assert.AreEqual("4", secondVoucher.S_IMG2_LEN.Trim());
}
示例2: RepositoryMock
public RepositoryMock()
{
List<Reply> replies = new List<Reply>
{
new Reply(){Body = "bdy1", Id = 1, TopicId = 1, Created = DateTime.Now},
new Reply(){Body = "bdy2", Id = 2, TopicId = 1, Created = DateTime.Now},
new Reply(){Body = "bdy3", Id = 3, TopicId = 1, Created = DateTime.Now},
new Reply(){Body = "bdy4", Id = 4, TopicId = 1, Created = DateTime.Now}
};
Mock<IMsgRepo> mockRepo = new Mock<IMsgRepo>();
mockRepo.Setup(m => m.GetReplies()).Returns(replies.AsQueryable);
mockRepo.Setup(m => m.FindById(
It.IsAny<int>()))
.Returns((int i) => replies.Single(x => x.Id == i));
mockRepo.Setup(m => m.DeleteReply(It.IsAny<int>()))
.Returns(
(int deleteId) =>
{
var replyToDelete = replies.Single(r => r.Id == deleteId);
replies.Remove(replyToDelete);
return true;
});
mockRepo.Setup(m => m.InsertReply(
It.IsAny<Reply>())).Returns(
(Reply target) =>
{
DateTime now = DateTime.Now;
if (target.Id.Equals(default(int)))
{
target.Created = now;
target.Id = replies.Count() + 1;
replies.Add(target);
}
else
{
var orig = replies.Single(r => r.Id == target.Id);
if (orig == null)
return false;
orig.Body = target.Body;
orig.Created = now;
orig.TopicId = target.TopicId;
}
return true;
}
);
MockRepo = mockRepo.Object;
}
示例3: CallCleanupActions
/// <summary>
/// The call cleanup actions.
/// </summary>
/// <exception cref="Exception">Cleanup action failed.
/// </exception>
/// <exception cref="AggregateException">Multiple exceptions occured in Cleanup. See test log for more details.
/// </exception>
private void CallCleanupActions()
{
this.cleanupActions.Reverse();
var exceptions = new List<Exception>();
foreach (var action in this.cleanupActions)
{
try
{
action();
}
catch (Exception ex)
{
exceptions.Add(ex);
Console.WriteLine("Cleanup action failed: " + ex);
}
}
if (exceptions.Count == 0)
{
return;
}
if (exceptions.Count == 1)
{
throw exceptions.Single();
}
throw new AggregateException(
"Multiple exceptions occured in Cleanup. See test log for more details",
exceptions);
}
示例4: TrackEventWillSendPropertiesIfProvidedInline
public void TrackEventWillSendPropertiesIfProvidedInline()
{
var sentTelemetry = new List<ITelemetry>();
var client = this.InitializeTelemetryClient(sentTelemetry);
client.TrackEvent("Test", new Dictionary<string, string> { { "blah", "yoyo" } });
var eventTelemetry = (EventTelemetry)sentTelemetry.Single();
Assert.Equal("yoyo", eventTelemetry.Properties["blah"]);
}
示例5: TrackEventSendsEventTelemetryWithSpecifiedObjectTelemetry
public void TrackEventSendsEventTelemetryWithSpecifiedObjectTelemetry()
{
var sentTelemetry = new List<ITelemetry>();
var client = this.InitializeTelemetryClient(sentTelemetry);
client.TrackEvent(new EventTelemetry("TestEvent"));
var eventTelemetry = (EventTelemetry)sentTelemetry.Single();
Assert.Equal("TestEvent", eventTelemetry.Name);
}
示例6: TrackEventSendsEventTelemetryWithSpecifiedNameToProvideSimplestWayOfSendingEventTelemetry
public void TrackEventSendsEventTelemetryWithSpecifiedNameToProvideSimplestWayOfSendingEventTelemetry()
{
var sentTelemetry = new List<ITelemetry>();
var client = this.InitializeTelemetryClient(sentTelemetry);
client.TrackEvent("TestEvent");
var eventTelemetry = (EventTelemetry)sentTelemetry.Single();
Assert.Equal("TestEvent", eventTelemetry.Name);
}
示例7: TrackEventWillUseRequiredFieldTextForTheEventNameWhenTheEventNameIsEmptyToHideUserErrors
public void TrackEventWillUseRequiredFieldTextForTheEventNameWhenTheEventNameIsEmptyToHideUserErrors()
{
var sentTelemetry = new List<ITelemetry>();
var client = this.InitializeTelemetryClient(sentTelemetry);
client.TrackEvent((string)null);
var eventTelemetry = (EventTelemetry)sentTelemetry.Single();
Assert.Contains(RequiredFieldText, eventTelemetry.Name, StringComparison.OrdinalIgnoreCase);
}
示例8: ComplexType_CustomValidator_MultipleMemberNames
public void ComplexType_CustomValidator_MultipleMemberNames()
{
// ensure TDPs are registered
DomainServiceDescription.GetDescription(typeof(ComplexTypes_TestService));
ComplexType_Parent entity = new ComplexType_Parent
{
ID = 1,
ContactInfo =
new ContactInfo
{
Name = "Mathew",
HomeAddress = new Address { AddressLine1 = "47 South Wynn Rd.", City = "Oregon", State = "OH" },
PrimaryPhone = new Phone { AreaCode = "419", Number = "693-6096" }
},
};
// configure multi member validation errors
DynamicTestValidator.ForcedValidationResults.Clear();
ValidationResult contactResult = new ValidationResult("ContactInfo", new string[] { "Name", "PrimaryPhone" });
ValidationResult phoneResult = new ValidationResult("Phone", new string[] { "AreaCode", "Number" });
DynamicTestValidator.ForcedValidationResults[entity.ContactInfo] = contactResult;
DynamicTestValidator.ForcedValidationResults[typeof(Phone)] = phoneResult;
ValidationContext validationContext = ValidationUtilities.CreateValidationContext(entity, null);
List<ValidationResult> results = new List<ValidationResult>();
bool isValid = ValidationUtilities.TryValidateObject(entity, validationContext, results);
Assert.IsFalse(isValid);
// Verify that the member names have been transformed into full paths
ValidationResult result = results.Single(q => q.ErrorMessage == "ContactInfo-ContactInfo");
string[] memberNames = result.MemberNames.ToArray();
Assert.AreEqual(2, memberNames.Length);
Assert.IsTrue(memberNames.Contains("ContactInfo.Name"));
Assert.IsTrue(memberNames.Contains("ContactInfo.PrimaryPhone"));
// here we expect member names to be transformed into full paths
result = results.Single(q => q.ErrorMessage == "Phone-TypeLevel");
memberNames = result.MemberNames.ToArray();
Assert.AreEqual(2, memberNames.Length);
Assert.IsTrue(memberNames.Contains("ContactInfo.PrimaryPhone.AreaCode"));
Assert.IsTrue(memberNames.Contains("ContactInfo.PrimaryPhone.Number"));
}
示例9: FirstOrDefaultAndSigle_Test
public void FirstOrDefaultAndSigle_Test()
{
IList<User> list = new List<User>();
list.Add(new User() { Id = 1, Name = "zhangsan1", Age = 18, Address = "四川" });
list.Add(new User() { Id = 2, Name = "zhangsan2", Age = 18, Address = "四川" });
list.Add(new User() { Id = 3, Name = "zhangsan3", Age = 18, Address = "四川" });
list.Add(new User() { Id = 4, Name = "zhangsan4", Age = 18, Address = "四川" });
list.Add(new User() { Id = 5, Name = "zhangsan5", Age = 18, Address = "四川" });
IQueryable<User> query = list.AsQueryable();
Assert.AreEqual(list.First(), query.FirstOrDefault());
Assert.AreEqual(null, query.FirstOrDefault(o => o.Age == 2));
Assert.AreEqual(list.Single(), query.Single());
Assert.AreEqual(null, query.Single(o => o.Age == 2));
}
示例10: GetTest1
public void GetTest1()
{
_repository = new Mock<IBookRepository>();
_library = new List<Book>
{
new Book() {ID = 1, Title = "Developing ASP.NET MVC 4 Web Applications",VolumeId = "7thhkgEACAAJ"},
new Book() {ID = 2, Title = "Developing Web Applications with Visual Basic.NET and ASP.NET",VolumeId = "L7071Dj5et4C"},
new Book() {ID = 3, Title = "The Kill Bill Diary",VolumeId = "5EGJAwAAQBAJ"}
};
_repository.Setup(x => x.Get(It.IsAny<int>()))
.Returns((int i) => _library.Single(bo => bo.ID == i));
var bookThatExists = _repository.Object.Get(1);
Assert.IsNotNull(bookThatExists);
}
示例11: DoesRepositoryWork
public DoesRepositoryWork()
{
List<Products> products = new List<Products>()
{
new Products
{
Id = 1,
Name = "Margaritha",
Price = (decimal) 10.0
},
new Products
{
Id = 2,
Name = "Fuji",
Price = (decimal) 20.0
},
new Products
{
Id = 3,
Name = "User",
Price = (decimal) 30.0
},
};
Mock<IRepository<Products>> mockRepo = new Mock<IRepository<Products>>();
mockRepo.Setup(m => m.GetList()).Returns(products);
mockRepo.Setup(m => m.GetEntity(It.IsAny<int>()))
.Returns((int i) => products.Single(x => x.Id == i));
mockRepo.Setup(m => m.AddEntity(It.IsAny<Products>())).Returns((Products product) =>
{
products.Add(product);
return product;
});
mockRepo.Setup(m => m.DeleteEntity(It.IsAny<Products>())).Returns((Products product) =>
{
products.Remove(product);
return product;
});
this.repository = mockRepo.Object;
}
示例12: PingLocalhostWillNotFail
public void PingLocalhostWillNotFail()
{
const string HOST = "127.0.0.1";
List<ToolPing> responseList = new List<ToolPing>();
Exception responseException = null;
ITikCommand pingCommand = Connection.LoadAsync<ToolPing>(
ping => responseList.Add(ping), //read callback
exception => responseException = exception, //exception callback
Connection.CreateParameter("address", HOST),
Connection.CreateParameter("count", "1"),
Connection.CreateParameter("size", "64"));
Thread.Sleep(2 * 1000);
Assert.IsNull(responseException);
Assert.AreEqual(responseList.Count, 1);
Assert.AreEqual(responseList.Single().Host, HOST);
}
示例13: GetUserStock_with_id_must_return_stock_from_context
public async Task GetUserStock_with_id_must_return_stock_from_context()
{
var data = new List<UserStock>
{
new UserStock {ID = 0, Name = "DAX"},
new UserStock {ID = 1, Name = "NYSE"}
}.AsQueryable();
var mockSet = new Mock<DbSet<UserStock>>();
mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0])));
var mockContext = new Mock<IStockExchangeDbContext>();
mockContext.Setup(c => c.UserStocks).Returns(mockSet.Object);
var service = new UserStocksController(mockContext.Object);
var result = await service.GetUserStock(0);
Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<UserStock>));
var conResult = result as OkNegotiatedContentResult<UserStock>;
Assert.IsNotNull(conResult);
Assert.AreEqual(data.Single(us => us.ID == 0), conResult.Content);
}
示例14: GetRefactoringResult
internal static string GetRefactoringResult(string language, CodeRefactoringProvider codeRefactoringProvider, string oldSource, TextSpan span, string equivalenceKey)
{
var document = CodeAnalysisHelper.CreateDocument(oldSource, language);
var actions = new List<CodeAction>();
var context = new CodeRefactoringContext(document, span, (a) => actions.Add(a), CancellationToken.None);
codeRefactoringProvider.ComputeRefactoringsAsync(context).Wait();
if (equivalenceKey != null)
{
document = CodeAnalysisHelper.ApplyFix(document, actions.Single(n => n.EquivalenceKey == equivalenceKey));
}
else
{
document = CodeAnalysisHelper.ApplyFix(document, actions[0]);
}
var newSource = CodeAnalysisHelper.GetStringFromDocument(document);
return newSource;
}
示例15: TrackTraceSendsTraceTelemetryWithSpecifiedObjectTelemetry
public void TrackTraceSendsTraceTelemetryWithSpecifiedObjectTelemetry()
{
var sentTelemetry = new List<ITelemetry>();
var client = this.InitializeTelemetryClient(sentTelemetry);
client.TrackTrace(new TraceTelemetry { Message = "TestTrace" });
var trace = (TraceTelemetry)sentTelemetry.Single();
Assert.Equal("TestTrace", trace.Message);
}