public void ByValue_Enumerable_CanDisallowNull() { var data = new[] { new EmailAddress { Value = FakeData.Email(), }, new EmailAddress { Value = FakeData.Email(), }, new EmailAddress { Value = FakeData.Email(), }, }; data.AsEnumerable().ByValue(data[0].Value, false).ShouldNotBeNull(); var exception = Assert.Throws<InvalidOperationException>(() => data.AsEnumerable().ByValue(FakeData.Email(), false)); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }
private static void Merge(System.Data.DataTable DestTable, System.Data.DataTable SrcTable) { string pk = DestTable.PrimaryKey[0].ColumnName; System.Data.DataRow[] pkChangedRows = DestTable.AsEnumerable().Where(p => p.RowState == DataRowState.Modified && !p[pk, DataRowVersion.Original].Equals(p[pk, DataRowVersion.Current])).ToArray(); try { //When PK has changed, move row to added state foreach (System.Data.DataRow dr in pkChangedRows) { dr.AcceptChanges(); dr.SetAdded(); } DestTable.Merge(SrcTable); } finally { //And when back to modifyed foreach (System.Data.DataRow dr in pkChangedRows) { dr.AcceptChanges(); dr.SetModified(); } } }
public void ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInIt() { var array = new[,] { { 1, 2 }, { 3, 4 } }; var list = array.AsEnumerable(); CollectionAssert.AreEquivalent(list, array); }
static void Main(string[] args) { var a = new[] { new Program() }; // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201401/20140120/avg var w = a.AsEnumerable().Where(x => x.Visible); }
public void ByName_Enumerable_CanAllowNull() { var data = new[] { new User { Name = FakeData.String() }, new User { Name = FakeData.String() }, new User { Name = FakeData.String() }, }; data.AsEnumerable().ByName(FakeData.String()).ShouldBeNull(); }
public void ByValue_Enumerable_CanAllowNull() { var data = new[] { new EmailAddress { Value = FakeData.Email(), }, new EmailAddress { Value = FakeData.Email(), }, new EmailAddress { Value = FakeData.Email(), }, }; data.AsEnumerable().ByValue(FakeData.Email()).ShouldBeNull(); }
public void ByTicket_Enumerable_CanAllowNull() { var data = new[] { new EmailVerification { Ticket = FakeData.String(), }, new EmailVerification { Ticket = FakeData.String(), }, new EmailVerification { Ticket = FakeData.String(), }, }; data.AsEnumerable().ByTicket(FakeData.String()).ShouldBeNull(); }
public void Get_All_Persons() { // Arrange var allPersons = new[] { new Library.Entity.Person {FirstName = "John", LastName = "McClung", MiddleName = "Paul", Notes = "Crazy as can be"}, new Library.Entity.Person {FirstName = "Katie", LastName = "McClung", MiddleName = "Elane", Notes = "Just as crazy as John"} }; var service = Mock.Of<IPersonService>(s => s.All(null, null, "LastName") == allPersons.AsEnumerable()); var controller = new PersonController(service); // Act var result = controller.Get(null, null, "LastName") as OkNegotiatedContentResult<IEnumerable<Web.Models.Person>>; var personModels = allPersons.AsEnumerable().ToModel(); // Assert Assert.NotNull(result); Assert.True(personModels.SequenceEqual(result.Content)); }
public void ToList_GivenAMultiDimensionalArray_ReturnsAnArrayWithAllItemsInTheCorrectOrder() { var array = new[,] { { 1, 2 }, { 3, 4 } }; var list = array.AsEnumerable().ToList(); Assert.AreEqual(list[0], array[0, 0]); Assert.AreEqual(list[1], array[1, 0]); Assert.AreEqual(list[2], array[0, 1]); Assert.AreEqual(list[3], array[1, 1]); }
public void ByUserId_Enumerable_CanDisallowNull() { var userId = FakeData.Id(); var otherUserId1 = FakeData.Id(userId); var otherUserId2 = FakeData.Id(userId, otherUserId1); var data = new[] { new LocalMembership { User = new ProxiedUser(otherUserId1), }, new LocalMembership { User = new ProxiedUser(userId), }, new LocalMembership { User = new ProxiedUser(otherUserId2), }, }; data.AsEnumerable().ByUserId(data[1].User.Id, false).ShouldNotBeNull(); var otherUserId3 = FakeData.Id(userId, otherUserId1, otherUserId2); var exception = Assert.Throws<InvalidOperationException>(() => data.AsEnumerable().ByUserId(otherUserId3, false)); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }
public void ConstructorShouldAddFileTypeFilters() { // arrange var expected = new[] { "*.*", "*.txt", "*.csv" }; // act var interaction = new SelectFolderInteraction( "", expected ); var actual = interaction.FileTypeFilter; // assert Assert.Equal( expected.AsEnumerable(), actual.AsEnumerable() ); }
public void When_the_sequence_contains_more_than_a_single_point_the_Min_point_equals_the_element_wise_minimum_of_the_sequence() { var points = new[] { new Point(1, 2, 3), new Point(2, 3, 4), new Point(4, 5, 6), new Point(-1, 3, 7), new Point(0, 0, -10) }; var aabb = AxisAlignedBoundingBox.FromPoints(points.AsEnumerable()); Assert.Equal(new Point(-1, 0, -10), aabb.Min); }
public void ByUserId_Enumerable_CanAllowNull() { var userId = FakeData.Id(); var otherUserId1 = FakeData.Id(userId); var otherUserId2 = FakeData.Id(userId, otherUserId1); var data = new[] { new LocalMembership { User = new ProxiedUser(otherUserId1), }, new LocalMembership { User = new ProxiedUser(userId), }, new LocalMembership { User = new ProxiedUser(otherUserId2), }, }; var otherUserId3 = FakeData.Id(userId, otherUserId1, otherUserId2); data.AsEnumerable().ByUserId(otherUserId3).ShouldBeNull(); }
public void TestTryEnumerable() { var expected = new[] {2, 3, 4, 5, 6}; var initital = new[] {1, 2, 3, 4, 5}; var @try = Try.Attempt(() => initital.AsEnumerable()).ToTryEnumerable(); var temp = (from num in @try select num + 1) .Out(); var result = temp.Match( success: BasicFunctions.Identity, failure: ex => Enumerable.Empty<int>()); Assert.IsTrue(TestUtils.AreEqual(result, expected)); }
public void ByUserId_Enumerable_FiltersByUserId() { var userId = FakeData.Id(); var data = new[] { new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), }, new RemoteMembership { UserId = userId, }, new RemoteMembership { UserId = userId, }, new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), }, new RemoteMembership { UserId = FakeData.Id(canNotBe: userId), }, new RemoteMembership { UserId = userId, }, }; var results = data.AsEnumerable().ByUserId(userId).ToArray(); results.ShouldNotBeNull(); results.Length.ShouldEqual(3); }
public void Should_ignore_overriden_parent_properties() { // given PropertyInfo property = new TestPropertyInfo(GetType()); var child = new { EntityType = typeof(IDerivedLevel2), Properties = CreateProperty(property, new Uri("urn:in:child")).AsEnumerable(), }.ActLike<IEntityMappingProvider>(); var parent = new { EntityType = typeof(IDerived), Properties = CreateProperty(property, new Uri("urn:in:parent")).AsEnumerable() }.ActLike<IEntityMappingProvider>(); // when var provider = new InheritanceTreeProvider(child, parent.AsEnumerable()); // then provider.Properties.Should().HaveCount(1); provider.Properties.Single().GetTerm(_ontology).Should().Be(new Uri("urn:in:child")); }
public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter() { var contactsServiceMock = new Mock<IContactsService>(); var resultMock = new Mock<IAsyncResult>(); var contacts = new[] { new Contact { EmailAddress = "email" }, new Contact { } }; contactsServiceMock .Setup(svc => svc.GetContactsAsync()) .Returns(Task.FromResult(contacts.AsEnumerable())); Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>(); regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?To=email")) .Verifiable(); IRegionManager regionManager = regionManagerMock.Object; var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts); viewModel.Contacts.MoveCurrentToFirst(); viewModel.EmailContactCommand.Execute(null); regionManagerMock.VerifyAll(); }
public void ExportRequestPay(string templateFile, DateTime rptDate, string currency, System.Data.DataTable shippingDt, System.Data.DataTable dtlDt, System.Data.DataTable retrieveDt, System.Data.DataTable iqcDt , System.Data.DataTable pricingDt, System.Data.DataTable exDt, List<tinprequestpaydtl> lstRequestPayDtl) { try { OpenExcel(templatePath + templateFile+".xls", 1); app.ActiveWindow.DisplayGridlines = false; string customerId = ""; string checkType = ""; string lang = "ZH"; List<tsysstaticvalue> lstStaticValue = GENLSYS.MES.Common.Parameter.CURRENT_STATIC_VALUE as List<tsysstaticvalue>; var langq = from p in lstStaticValue where p.svvalue.Equals(templateFile) select p; if (langq.Count() > 0) { lang = langq.ElementAt(0).svresourceid.ToUpper(); } #region Header //入库时间 var custordernoq = (from p in dtlDt.AsEnumerable() select p["custorderno"].ToString()).Distinct(); List<string> lstOrder = new List<string>(); foreach (string custorderno in custordernoq) { if (!lstOrder.Contains(custorderno)) { lstOrder.Add(custorderno); } } setCellValue(5, 9, "契約NO," + shippingDt.Rows[0]["shippingno"].ToString()); DateTime rdate = GetReceiveDate(lstOrder.ToArray<string>()); setCellValue(11, 3, rdate); ((Range)workSheet.Cells[11, 3]).NumberFormat = "yyyy-MM-dd"; setCellValue(7, 5, currency); if (shippingDt.Rows.Count > 0) { setCellValue(4, 3, shippingDt.Rows[0]["invoicetitle"].ToString()); setCellValue(12, 3, Convert.ToDateTime(shippingDt.Rows[0]["shippeddate"])); ((Range)workSheet.Cells[12, 3]).NumberFormat = "yyyy-MM-dd"; setCellValue(6, 9, Convert.ToDateTime(shippingDt.Rows[0]["shippeddate"])); ((Range)workSheet.Cells[6, 9]).NumberFormat = "yyyy年MM月dd日"; setCellValue(13, 3, shippingDt.Rows[0]["customername"]); customerId = shippingDt.Rows[0]["customerid"].ToString(); } #endregion int startRow = 17; int rownum = 0; #region 一次检 var qByStyleNo = from p in dtlDt.AsEnumerable() group p by new { custorderno = p["custorderno"].ToString(), styleno = p["styleno"].ToString(), factory = p["factory"].ToString(), checktype = p["checktype"].ToString() } into g select new { g.Key.custorderno, g.Key.styleno, g.Key.factory, g.Key.checktype, totalpairqty = g.Sum(p => Convert.ToInt16(p["pairqty"])) }; foreach (var data in qByStyleNo) { int row = startRow + rownum; ((Range)workSheet.Rows[row, Type.Missing]).Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing); setCellValue(row, 2, data.factory); setCellValue(row, 3, data.custorderno); ((Range)workSheet.Cells[row, 3]).NumberFormatLocal = "@"; setCellValue(row, 4, data.styleno); setCellValue(row, 8, data.totalpairqty); if (data.checktype.Equals("I")) { setCellValue(row, 5, lang.Equals("ZH") ? "检品" : "一次検品"); } else if (data.checktype.Equals("X")) { setCellValue(row, 5, lang.Equals("ZH") ? "X线" : "X線"); } else { setCellValue(row, 5, lang.Equals("ZH") ? "检品+X线" : "一次検品、X線"); } var iqcq = from p in iqcDt.AsEnumerable() where p["styleno"].ToString().Equals(data.styleno.ToString()) && p["customerid"].ToString().Equals(customerId) select p; if (iqcq.Count() > 0) { string shoeCategory = iqcq.ElementAt(0)["category"].ToString(); Double bootHeight = Convert.ToDouble(iqcq.ElementAt(0)["bootheight"]); setCellValue(row, 6, GetShoeCategory(shoeCategory, lang)); var pricingq = from p in pricingDt.AsEnumerable() where p["category"].ToString().Equals(shoeCategory) && Convert.ToDouble(p["sbootheight"]) <= bootHeight && Convert.ToDouble(p["ebootheight"]) >= bootHeight && p["checktype"].ToString().Equals(data.checktype) select p; if (pricingq.Count() > 0) { setCellValue(row, 9, pricingq.ElementAt(0)["unit"].ToString()); if (!pricingq.ElementAt(0)["currency"].ToString().Trim().Equals(currency)) { var exckq = from p in exDt.AsEnumerable() where p["fromcurrency"].ToString().Equals(pricingq.ElementAt(0)["currency"].ToString()) && p["tocurrency"].ToString().Equals(currency) select p; if (exckq.Count() > 0) { setCellValue(row, 7, Convert.ToDouble(pricingq.ElementAt(0)["price"]) * Convert.ToDouble(exckq.ElementAt(0)["rate"])); } } else { setCellValue(row, 7, pricingq.ElementAt(0)["price"]); } SetCurrencyFormat((Range)workSheet.Cells[row, 7], currency, true); } } ((Range)workSheet.Cells[row, 10]).Formula = "=G"+row+"*H"+row; SetCurrencyFormat((Range)workSheet.Cells[row, 10],currency,true); if (checkType.Equals("")) { checkType = data.checktype; } else { if (checkType.Equals(data.checktype)) { checkType = "IX"; } } rownum++; } #endregion #region 再检 var qRetrieve = from p in retrieveDt.AsEnumerable() where !p["checktype"].ToString().Equals("X") group p by new { custorderno = p["custorderno"].ToString(), styleno = p["styleno"].ToString(), factory = p["factory"].ToString(), checktype = p["checktype"].ToString() } into g select new { g.Key.custorderno, g.Key.styleno, g.Key.factory, g.Key.checktype, totalpairqty = g.Sum(p => Convert.ToInt16(p["pairqty"])) }; foreach (var data in qRetrieve) { int row = startRow + rownum; ((Range)workSheet.Rows[row, Type.Missing]).Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing); setCellValue(row, 2, data.factory); setCellValue(row, 3, data.custorderno); ((Range)workSheet.Cells[row, 3]).NumberFormatLocal = "@"; setCellValue(row, 4, data.styleno); setCellValue(row, 8, data.totalpairqty); if (data.checktype.Equals("I")) { //setCellValue(row, 5, "检品再检"); setCellValue(row, 5, lang.Equals("ZH") ? "再检" : "再検品"); } //else if (data.checktype.Equals("X")) //{ // //setCellValue(row, 5, "X线再检"); // setCellValue(row, 5, "再検品"); //} else { //setCellValue(row, 5, "全检再检"); setCellValue(row, 5, lang.Equals("ZH") ? "再检" : "再検品"); } var iqcq = from p in iqcDt.AsEnumerable() where p["styleno"].ToString().Equals(data.styleno.ToString()) && p["customerid"].ToString().Equals(customerId) select p; if (iqcq.Count() > 0) { string shoeCategory = iqcq.ElementAt(0)["category"].ToString(); Double bootHeight = Convert.ToDouble(iqcq.ElementAt(0)["bootheight"]); setCellValue(row, 6, GetShoeCategory(shoeCategory,lang)); var pricingq = from p in pricingDt.AsEnumerable() where p["category"].ToString().Equals(shoeCategory) && Convert.ToDouble(p["sbootheight"]) <= bootHeight && Convert.ToDouble(p["ebootheight"]) >= bootHeight && p["checktype"].ToString().Equals(data.checktype.ToString().Equals("IX")?"I":data.checktype) select p; if (pricingq.Count() > 0) { setCellValue(row, 9, pricingq.ElementAt(0)["unit"].ToString()); double price = 0; if (pricingq.ElementAt(0)["reworkprice"] == null || Convert.ToDouble(pricingq.ElementAt(0)["reworkprice"]) == 0) { price = Convert.ToDouble(pricingq.ElementAt(0)["price"]) * Convert.ToDouble(pricingq.ElementAt(0)["reworkratio"]); } else { price = Convert.ToDouble(pricingq.ElementAt(0)["reworkprice"]); } if (!pricingq.ElementAt(0)["currency"].ToString().Trim().Equals(currency)) { var exckq = from p in exDt.AsEnumerable() where p["fromcurrency"].ToString().Equals(pricingq.ElementAt(0)["currency"].ToString()) && p["tocurrency"].ToString().Equals(currency) select p; if (exckq.Count() > 0) { setCellValue(row, 7, price * Convert.ToDouble(exckq.ElementAt(0)["rate"])); } } else { setCellValue(row, 7, price); } SetCurrencyFormat((Range)workSheet.Cells[row, 7], currency, true); } } ((Range)workSheet.Cells[row, 10]).Formula = "=G" + row + "*H" + row; SetCurrencyFormat((Range)workSheet.Cells[row, 10], currency, true); rownum++; } #endregion for (int i = 17; i < startRow + rownum; i++) { for (int j = 2; j <= 10; j++) { ((Range)workSheet.Cells[i, j]).Borders.LineStyle = 1; ((Range)workSheet.Cells[i, j]).ShrinkToFit = true; } } #region 其他费用 foreach (tinprequestpaydtl dtl in lstRequestPayDtl) { int row = startRow + rownum; ((Range)workSheet.Rows[row, Type.Missing]).Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing); setCellValue(row, 2, dtl.itemname); setCellValue(row, 8, dtl.qty); setCellValue(row, 9, dtl.unit); if (!dtl.currency.Trim().Equals(currency)) { var exckq = from p in exDt.AsEnumerable() where p["fromcurrency"].ToString().Equals(dtl.currency) && p["tocurrency"].ToString().Equals(currency) select p; if (exckq.Count() > 0) { setCellValue(row, 7, Convert.ToDouble(dtl.price) * Convert.ToDouble(exckq.ElementAt(0)["rate"])); } } else { setCellValue(row, 7, dtl.price); } SetCurrencyFormat((Range)workSheet.Cells[row, 7], currency, true); ((Range)workSheet.Cells[row, 10]).Formula = "=G" + row + "*H" + row; SetCurrencyFormat((Range)workSheet.Cells[row, 10], currency, true); rownum++; } for (int i = startRow + rownum -lstRequestPayDtl.Count; i < startRow + rownum; i++) { workSheet.get_Range("B" + i, "F" + i).MergeCells = true; workSheet.get_Range("B" + i, "F" + i).Borders.LineStyle = 1; ((Range)workSheet.Cells[i, 7]).Borders.LineStyle = 1; ((Range)workSheet.Cells[i, 8]).Borders.LineStyle = 1; ((Range)workSheet.Cells[i, 9]).Borders.LineStyle = 1; ((Range)workSheet.Cells[i, 10]).Borders.LineStyle = 1; } #endregion Range rowRange = workSheet.Range["B17", "J" + (startRow + rownum - 1)]; FormatCondition cond = rowRange.FormatConditions.Add(XlFormatConditionType.xlExpression, Type.Missing, "=MOD(ROW(),2)=0"); cond.Interior.Color = Color.FromArgb(255, 255, 153); ((Range)workSheet.Cells[startRow + rownum, 10]).Formula = "=SUM(J" + startRow + ":J" + (startRow+rownum-1)+")"; ((Range)workSheet.Cells[startRow + rownum, 10]).HorizontalAlignment = XlHAlign.xlHAlignCenter; SetCurrencyFormat((Range)workSheet.Cells[startRow + rownum, 10], currency, true); ((Range)workSheet.Cells[7, 6]).Formula = "=J" + (startRow + rownum); SetCurrencyFormat((Range)workSheet.Cells[7,6], currency, false); if (checkType.Equals("I")){ setCellValue(10, 3, lang.Equals("ZH") ? "检品" : "一次検品"); }else if (checkType.Equals("X")){ setCellValue(10, 3, lang.Equals("ZH") ? "X线" : "X線"); }else{ setCellValue(10, 3, lang.Equals("ZH") ? "检品+X线" : "一次検品、X線"); } ((Range)workSheet.Cells[7, 6]).Formula = "=J" + (startRow + rownum); saveAsExcel(templateFile + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); app.Visible = true; } catch (Exception ex) { CloseExcel(); throw ex; } }
public async Task WriteUserTagsAsync_ClearFalseExistingTagsSomeEquals_OnlyTags() { // Arrange var target = Substitute.ForPartsOf<TagsOperation>(_fileSystemHelper, _file, _path, _tagHelper); var file = @"C:\Temp\UnknownFile.txt"; _file.Exists(file).Returns(true); var tags = new[]{ "Tag1", "Tag2", "Tag3" }; var existingTags = new[]{ "Tag2", "Tag3", "Tag4" }; target.When(x => x.ReadUserTagsAsync(file)).DoNotCallBase(); target.ReadUserTagsAsync(file).Returns(Task.FromResult(existingTags.AsEnumerable())); // Act await _target.WriteUserTagsAsync(file, tags, false); // Assert var expected = new[]{ "Tag1", "Tag2", "Tag3", "Tag4" }; await _tagHelper.Received(1).WriteTagAsync(file, T.Keywords, Arg.Do<string[]>(t => CollectionAssert.AreEquivalent(expected.ToList(), t.ToList()))); }
public void ByUserId_Enumerable_FiltersByUserId() { var userId = FakeData.Id(); var data = new[] { new EmailAddress { Value = FakeData.Email(), UserId = FakeData.Id(canNotBe: userId), }, new EmailAddress { Value = FakeData.Email(), UserId = userId, }, new EmailAddress { Value = FakeData.Email(), UserId = userId, }, new EmailAddress { Value = FakeData.Email(), UserId = FakeData.Id(canNotBe: userId), }, new EmailAddress { Value = FakeData.Email(), UserId = FakeData.Id(canNotBe: userId), }, new EmailAddress { Value = FakeData.Email(), UserId = userId, }, }; var results = data.AsEnumerable().ByUserId(userId).ToArray(); results.ShouldNotBeNull(); results.Length.ShouldEqual(3); }
public void ExportFinalFailedRpt(System.Data.DataTable dt) { try { OpenExcel(templatePath + "FinalFailedRpt.xls", 1); if (dt.Rows.Count > 0) { setCellValue(5, 2, dt.Rows[0]["customername"].ToString()); setCellValue(5, 5, dt.Rows[0]["custorderno"].ToString()); var sumq = from p in dt.AsEnumerable() group p by new { custorderno = p["custorderno"].ToString(), styleno = p["styleno"].ToString(), color = p["color"].ToString(), size = p["size"].ToString() } into q select new { custorderno = q.Key.custorderno, styleno = q.Key.styleno, color = q.Key.color, size = q.Key.size, sumpairqty = q.Sum(p => Convert.ToInt16(p["pairqty"])) }; int beforeRow = 6; foreach (var s in sumq) { int nowRow = ++beforeRow; ((Range)workSheet.Rows[nowRow, Type.Missing]).Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing); workSheet.get_Range("A" + nowRow, "B" + nowRow).MergeCells = true; workSheet.get_Range("C" + nowRow, "D" + nowRow).MergeCells = true; workSheet.get_Range("G" + nowRow, "H" + nowRow).MergeCells = true; ((Range)workSheet.Cells[nowRow, 1]).NumberFormatLocal = "@"; ((Range)workSheet.Cells[nowRow, 3]).NumberFormatLocal = "@"; ((Range)workSheet.Cells[nowRow, 5]).NumberFormatLocal = "@"; setCellValue(nowRow, 1, s.styleno.ToString()); setCellValue(nowRow, 3, s.color.ToString()); setCellValue(nowRow, 5, s.size); setCellValue(nowRow, 6, s.sumpairqty); } if (beforeRow > 6) { ((Range)workSheet.Cells[beforeRow + 1, 6]).Formula = "=SUM(F7:F" + beforeRow + ")"; //((Range)workSheet.Cells[beforeRow + 1, 6]).Font.a } } saveAsExcel("FinalFailedRpt_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); app.Visible = true; } catch (Exception ex) { CloseExcel(); throw ex; } }
public void InheritedFromAny_CallsBuilder_WithAFilterAskingTypeFilterIfItIsInherited() { var givenTypes = new[] { typeof(object), typeof(double) }; var type = typeof(int); this.SetupStoreFilter(); this.SetupIsTypeInheritedFromAny(type, givenTypes); this.testee.InheritedFromAny(givenTypes.AsEnumerable()); var result = this.filter(type); result.Should().BeTrue(); this.typeFilterMock.VerifyAll(); }
public void Parameter_List_Definition() { var sources = (IReadOnlyList<string>)Array.Empty<string>(); Parse("source1.cs source2.cs", syntax => { syntax.DefineParameterList("sources", ref sources, string.Empty); }); var expected = new[] { "source1.cs", "source2.cs" }; var actual = sources; Assert.Equal(expected.AsEnumerable(), actual); }
private bool IsOpIdInTable(System.Data.DataTable dt, int menuId, string operateType) { try { if (dt == null || dt.Rows.Count < 1) return false; var item = from dr in dt.AsEnumerable() where dr.Field<Int32>("MenuId") == menuId && dr.Field<Int32>("OperateType") == Convert.ToInt32(operateType) select dr; return item.Count() > 0; } catch { return false; } }
public void ByUserName_Enumerable_FiltersByUserName() { var userName = FakeData.String(); var user = new User { Name = userName, }; var data = new[] { new RemoteMembership { User = new User { Name = FakeData.String(), }, }, new RemoteMembership { User = user, }, new RemoteMembership { User = user, }, new RemoteMembership { User = new User { Name = FakeData.String(), }, }, new RemoteMembership { User = new User { Name = FakeData.String(), }, }, new RemoteMembership { User = user, }, }; var results = data.AsEnumerable().ByUserName(userName).ToArray(); results.ShouldNotBeNull(); results.Length.ShouldEqual(3); }
//public void ExportReport(System.Data.DataTable dataTableRpt, // System.Data.DataTable dataTableRptAvilability, List<ReportColumn> ColumnList, string PivotAlias, double Left, double Top) //{ // System.Data.DataTable dtPivot = new System.Data.DataTable(); // List<ReportColumn> usedColumnList = EntityGeneric.CloneList<ReportColumn>(ColumnList); // System.Data.DataTable dtTempPivot = PivotTable.GetInversedDataTable(dataTableRpt, "DataMember", "Username", "Duration", "0", true); // dtTempPivot.PrimaryKey = new DataColumn[] { dtTempPivot.Columns["Username"] }; // dataTableRptAvilability.PrimaryKey = new DataColumn[] { dataTableRptAvilability.Columns["Username"] }; // dtTempPivot.Columns.Add(GenerateTotalColumn(usedColumnList, dtTempPivot)); // dtPivot = dtTempPivot.Copy(); // dtPivot.Merge(dataTableRptAvilability); // AddSheet("PivotChart"); // CreateChart(dtPivot, GetSheet("PivotChart"), PivotAlias, usedColumnList, Left, Top); //} public void CreateChart(System.Data.DataTable pivotDataRange, Worksheet targetSheet, string chartName, List<ReportColumn> usedColumnList, double Left, double Top) { ChartObjects _ChartObjects = (ChartObjects)(targetSheet.ChartObjects(Type.Missing)); ChartObject _ChartObject = _ChartObjects.Add(Left, Top, 1200, 400); Chart _Chart = _ChartObject.Chart; _Chart.HasTitle = true; _Chart.ChartTitle.Text = chartName; _Chart.ChartTitle.Font.Size = 12; _Chart.Legend.Position = XlLegendPosition.xlLegendPositionBottom; SeriesCollection seriesCollection; seriesCollection = (SeriesCollection)_Chart.SeriesCollection(Type.Missing); foreach (ReportColumn cl in usedColumnList) { if (cl.ChartXAxis) continue; Series series = seriesCollection.NewSeries(); series.Name = cl.DisplayMember; series.XValues = pivotDataRange.AsEnumerable().Select(s => s.Field<string>("Username")).ToArray<string>(); series.Values = ConvertDTColumn2Array(pivotDataRange, cl.DataMember); series.ChartType = (XlChartType)cl.xlSeriesChartType; if (cl.xlSeriesLabelListOrientation != 0) { series.ApplyDataLabels(XlDataLabelsType.xlDataLabelsShowValue, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); series.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; foreach (Point point in (Points)series.Points()) { point.DataLabel.Orientation = (Microsoft.Office.Core.XlChartOrientation)cl.xlSeriesLabelListOrientation; } foreach (DataLabel label in (DataLabels)series.DataLabels()) { //label.Orientation = (Microsoft.Office.Core.XlChartOrientation)cl.xlSeriesLabelListOrientation; label.Position = (XlDataLabelPosition)cl.xlSeriesLabelListPosition; label.Top = cl.xlSeriesLabelListTop; } } } usedColumnList.Clear(); }
private bool IsIdInTable(System.Data.DataTable dt, int menuId) { try { if (dt == null || dt.Rows.Count < 1) return false; var item = from dr in dt.AsEnumerable() where dr.Field<Int32>("MenuId") == menuId select dr; return item.Count() > 0; } catch { return false; } }
public void ByUserNameAndLoginInfo_Enumerable_CanAllowNull() { var data = new[] { new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, }; var userName = FakeData.String(); var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); data.AsEnumerable().ByUserNameAndLoginInfo(userName, userLoginInfo).ShouldBeNull(); }
public void ZipAll_EnumerableOfEnumerables() { var array = new[] { Enumerable.Range(1, 10), Enumerable.Range(10, 10) }; var zipped = array.AsEnumerable().ZipAll(); var expected = new[] { 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17, 9, 18, 10, 19 }; Assert.IsTrue(zipped.SelectMany(x => x).Select(x => x.ValueOrDefault()).SequenceEqual(expected)); }
public void ByUserNameAndLoginInfo_Enumerable_CanDisallowNull() { var data = new[] { new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = new User { Name = FakeData.String(), } }, }; var existingEntity = data[0]; var userLoginInfo = new UserLoginInfo( existingEntity.LoginProvider, existingEntity.ProviderKey); data.AsEnumerable().ByUserNameAndLoginInfo(existingEntity.User.Name, userLoginInfo, false) .ShouldNotBeNull(); userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); var exception = Assert.Throws<InvalidOperationException>(() => data.AsEnumerable().ByUserNameAndLoginInfo(FakeData.String(), userLoginInfo, false)); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }