Best JustMockLite code snippet using Telerik.JustMock.Tests.Book.Item
PublicationDomainServiceTest.cs
Source:PublicationDomainServiceTest.cs
1using LexisNexis.Red.Common;2using LexisNexis.Red.Common.Business;3using LexisNexis.Red.Common.BusinessModel;4using LexisNexis.Red.Common.Database;5using LexisNexis.Red.Common.Entity;6using LexisNexis.Red.Common.HelpClass;7using LexisNexis.Red.Common.Interface;8using LexisNexis.Red.Common.Services;9using LexisNexis.Red.CommonTests.Impl;10using LexisNexis.Red.CommonTests.Interface;11using Newtonsoft.Json;12using NUnit.Framework;13using System;14using System.Collections.Generic;15using System.Diagnostics;16using System.Linq;17using System.Text;18using System.Threading;19using System.Threading.Tasks;20using Telerik.JustMock;21using Telerik.JustMock.AutoMock;22namespace LexisNexis.Red.CommonTests.Business23{24 [TestFixture, Category("PublicationDomainServiceTest")]25 public partial class PublicationDomainServiceTest26 {27 [Test]28 public void PublicationDomainService_VerifyNetwork()29 {30 domainContainer.Arrange<INetwork>(network => network.GetNetworkType()).IgnoreArguments().Returns(NetworkTypeEnum.Mobile);31 domainContainer.Arrange<INetwork>(network => network.GetFlowLimitation()).IgnoreArguments().Returns(long.Parse("20"));32 try33 {34 domainContainer.Instance.VerifyNetwork(30);35 }36 catch (ExceedLimitationException)37 {38 Assert.IsTrue(1 == 1);39 }40 catch (Exception)41 {42 throw;43 }44 try45 {46 domainContainer.Instance.VerifyNetwork(10);47 }48 catch (Exception)49 {50 throw;51 }52 domainContainer.Arrange<INetwork>(network => network.GetNetworkType()).IgnoreArguments().Returns(NetworkTypeEnum.None);53 try54 {55 domainContainer.Instance.VerifyNetwork(30);56 }57 catch (CusNetDisConnectedException)58 {59 Assert.IsTrue(1 == 1);60 }61 catch (Exception)62 {63 throw;64 }65 }66 [Test]67 public void GetAdditionalDlBooks()68 {69 List<DlBook> localBooks = new List<DlBook> 70 { 71 new DlBook{BookId=1, IsLoan=true, DlStatus=(short)DlStatusEnum.Downloaded, ValidTo=DateTime.Now.AddDays(10)},72 new DlBook{BookId=2, IsLoan=true, DlStatus=(short)DlStatusEnum.Downloaded,ValidTo=DateTime.Now.AddDays(10) },73 new DlBook{BookId=3, IsLoan=false, DlStatus=(short)DlStatusEnum.Downloaded, ValidTo=DateTime.Now.AddDays(10) },74 new DlBook{BookId=4, IsLoan=false, DlStatus=(short)DlStatusEnum.Downloaded, ValidTo=DateTime.Now.AddDays(-10) },75 new DlBook{BookId=5, IsLoan=false, DlStatus=(short)DlStatusEnum.NotdDownloaded, ValidTo=DateTime.Now.AddDays(-10)},76 new DlBook{BookId=6, IsLoan=false, DlStatus=(short)DlStatusEnum.NotdDownloaded, ValidTo=DateTime.Now.AddDays(10)},77 new DlBook{BookId=7, IsLoan=true, DlStatus=(short)DlStatusEnum.RemovedByUser,ValidTo=DateTime.Now.AddDays(10) },78 new DlBook{BookId=8, IsLoan=false, IsTrial=true, DlStatus=(short)DlStatusEnum.RemovedByUser, ValidTo=DateTime.Now.AddDays(10)},79 };80 var additionalBooks = domainContainer.Instance.GetAdditionalDlBooks(localBooks);81 Assert.IsTrue(additionalBooks.Count() == 2);82 foreach (var item in additionalBooks)83 {84 Assert.IsTrue(item.ValidTo.Value < DateTime.Now.Date);85 }86 }87 [Test]88 public async void RefreshLocalDlBook()89 {90 DlBook serverDl = new DlBook91 {92 SubCategory = "SubCategory",93 PracticeArea = "PracticeArea",94 AddedGuideCard = "AddedGuideCard",95 CurrentVersion = 20,96 Size = 200097 };98 DlBook localDl = new DlBook99 {100 DlStatus = (short)DlStatusEnum.NotdDownloaded101 };102 domainContainer.Arrange<IDeliveryService>((deliveryService) => deliveryService.DlMetadata(null)).IgnoreArguments()103 .Returns(GetDlMetadata());104 domainContainer.Arrange<IDeliveryService>((deliveryService) => deliveryService.DlVersionChangeHistory(null)).IgnoreArguments()105 .Returns(GetDlBookChangeHistory());106 await domainContainer.Instance.RefreshLocalDlBook(serverDl, localDl, "");107 Assert.IsTrue(localDl.SubCategory == serverDl.SubCategory);108 Assert.IsTrue(localDl.PracticeArea == serverDl.PracticeArea);109 var localAddedGuideCard = JsonConvert.DeserializeObject<List<GuideCard>>(localDl.AddedGuideCard);110 Assert.IsTrue(localAddedGuideCard[0].Name == serverDl.AddedGuideCard);111 Assert.IsTrue(localDl.LastDownloadedVersion == serverDl.CurrentVersion);112 Assert.IsTrue(localDl.LocalSize == serverDl.Size);113 }114 private Task<HttpResponse> GetDlBookChangeHistory()115 {116 Task<HttpResponse> changeHistory = new Task<HttpResponse>(() =>117 {118 return new HttpResponse119 {120 Content = JsonConvert.SerializeObject(new DlVersionChangeHistoryResponse121 {122 AddedGuideCard = new List<GuideCard> { new GuideCard { Name = "AddedGuideCard" } }123 }),124 IsSuccess = true125 };126 });127 changeHistory.Start();128 return changeHistory;129 }130 private Task<HttpResponse> GetDlMetadata()131 {132 Task<HttpResponse> metaDataTask = new Task<HttpResponse>(() =>133 {134 return new HttpResponse135 {136 Content = JsonConvert.SerializeObject(new DlMetadataDetails { SubCategory = "SubCategory", PracticeArea = "PracticeArea" }),137 IsSuccess = true138 };139 });140 metaDataTask.Start();141 return metaDataTask;142 }143 [Test]144 public void UpdateLocalDlBooks()145 {146 List<DlBook> localBooks = new List<DlBook> 147 { 148 new DlBook{ BookId=1, 149 IsLoan=true,150 DlStatus=(short)DlStatusEnum.Downloaded,151 LastDownloadedVersion=1,152 ValidTo=DateTime.Now.AddDays(10)},153 };154 List<DlBook> serverBooks = new List<DlBook> 155 { 156 new DlBook{BookId=1, IsLoan=true, CurrentVersion=20, ValidTo=DateTime.Now.AddDays(10)},157 new DlBook{BookId=2, IsLoan=true, ValidTo=DateTime.Now.AddDays(10) },158 new DlBook{BookId=3, IsLoan=false,ValidTo=DateTime.Now.AddDays(10) },159 new DlBook{BookId=6, IsLoan=false, ValidTo=DateTime.Now.AddDays(10)},160 };161 var publications = domainContainer.Instance.UpdateLocalDlBooks(serverBooks, localBooks);162 var publication = publications.FirstOrDefault(o => o.BookId == 1);163 Assert.IsTrue(publication.PublicationStatus == PublicationStatusEnum.RequireUpdate);164 Assert.IsTrue(publications.Count() == serverBooks.Count);165 }166 [Test]167 public void GetOnlineDlBooks()168 {169 domainContainer.Arrange<IDeliveryService>((deliveryService) => deliveryService.ListFileDetails(null)).IgnoreArguments()170 .Returns(ListFileDetails());171 var dlBooks = domainContainer.Instance.GetOnlineDlBooks("allen@lexis.com").Result;172 Assert.IsTrue(dlBooks.Count == 0);173 }174 private Task<HttpResponse> ListFileDetails()175 {176 Task<HttpResponse> metaDataTask = new Task<HttpResponse>(() =>177 {178 return new HttpResponse179 {180 Content = JsonConvert.SerializeObject(new DlFileList { DlBooks = new List<DlBook>() }),181 IsSuccess = true182 };183 });184 metaDataTask.Start();185 return metaDataTask;186 }187 }188}...
TaxCalcServiceTests.cs
Source:TaxCalcServiceTests.cs
...16 [Test()]17 public void CalculateTaxes_Input1_Test()18 {19 var expected = 1.50d;20 var transactionItems = new List<ITransactionItem>21 {22 MockUtil.MockTransaction(1, "book", 12.49d, ProductType.Book, false),23 MockUtil.MockTransaction(1, "music CD", 14.99d, ProductType.Taxable, false),24 MockUtil.MockTransaction(1, "chocolate bar", 0.85d, ProductType.Food, false),25 };26 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);27 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);28 var actual = sut.CalculateTaxes(transactionItems);29 Assert.That(actual, Is.EqualTo(expected));30 }31 [Test()]32 public void CalculateTaxes_Input2_Test()33 {34 var expected = 7.65d;35 var transactionItems = new List<ITransactionItem>36 {37 MockUtil.MockTransaction(1, "box of chocolates", 10.00d, ProductType.Food, true), 38 MockUtil.MockTransaction(1, "bottle of perfume", 47.50d, ProductType.Taxable, true),39 };40 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);41 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);42 var actual = sut.CalculateTaxes(transactionItems);43 Assert.That(actual, Is.EqualTo(expected));44 }45 [Test()]46 public void CalculateTaxes_Input3_Test()47 {48 var expected = 6.70;49 var transactionItems = new List<ITransactionItem>50 {51 MockUtil.MockTransaction(1, "bottle of perfume", 27.99d, ProductType.Taxable, true),52 MockUtil.MockTransaction(1, "bottle of perfume", 18.99d, ProductType.Taxable, false),53 MockUtil.MockTransaction(1, "packet of headache pills", 9.70d, ProductType.Medical, false),54 MockUtil.MockTransaction(1, "box of imported chocolates", 11.25d, ProductType.Food, true),55 };56 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);57 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);58 var actual = sut.CalculateTaxes(transactionItems);59 Assert.That(actual, Is.EqualTo(expected));60 }61 [Test()]62 public void CalculateTaxes_Input1_Book_NoTax_Test()63 {64 var expected = 0.0d;65 var transactionItems = new List<ITransactionItem>66 {67 MockUtil.MockTransaction(1, "book", 12.49d, ProductType.Book, false),68 };69 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);70 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);71 var actual = sut.CalculateTaxes(transactionItems);72 Assert.That(actual, Is.EqualTo(expected));73 }74 [Test()]75 public void CalculateTaxes_Input1_CD_150Tax_Test()76 {77 var expected = 1.50d;78 var transactionItems = new List<ITransactionItem>79 {80 MockUtil.MockTransaction(1, "music CD", 14.99d, ProductType.Taxable, false),81 };82 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);83 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);84 var actual = sut.CalculateTaxes(transactionItems);85 Assert.That(actual, Is.EqualTo(expected));86 }87 [Test()]88 public void CalculateTaxes_Input1_Choc_NoTax_Test()89 {90 var expected = 0.00d;91 var transactionItems = new List<ITransactionItem>92 {93 MockUtil.MockTransaction(1, "chocolate bar", 0.85d, ProductType.Food, false),94 };95 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);96 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);97 var actual = sut.CalculateTaxes(transactionItems);98 Assert.That(actual, Is.EqualTo(expected));99 }100 [Test()]101 public void CalculateTaxes_Input_multiple_Choc_NoTax_Test()102 {103 var expected = 0.00d;104 var transactionItems = new List<ITransactionItem>105 {106 MockUtil.MockTransaction(10, "chocolate bar", 0.85d, ProductType.Food, false),107 };108 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);109 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);110 var actual = sut.CalculateTaxes(transactionItems);111 Assert.That(actual, Is.EqualTo(expected));112 }113 [Test]114 public void CalculateTaxes_Input_multiple_CD_1500Tax_Test()115 {116 var expected = 15.00d;117 var transactionItems = new List<ITransactionItem>118 {119 MockUtil.MockTransaction(10, "music CD", 14.99d, ProductType.Taxable, false),120 };121 var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);122 var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);123 var actual = sut.CalculateTaxes(transactionItems);124 Assert.That(actual, Is.EqualTo(expected));125 }126 }127}...
PublicationUtilTest_GetPublicationOffline.cs
Source:PublicationUtilTest_GetPublicationOffline.cs
1using LexisNexis.Red.Common;2using LexisNexis.Red.Common.Business;3using LexisNexis.Red.Common.BusinessModel;4using LexisNexis.Red.Common.Database;5using LexisNexis.Red.Common.Entity;6using LexisNexis.Red.Common.HelpClass;7using LexisNexis.Red.Common.Interface;8using LexisNexis.Red.Common.Services;9using LexisNexis.Red.CommonTests.Impl;10using LexisNexis.Red.CommonTests.Interface;11using Newtonsoft.Json;12using NUnit.Framework;13using System;14using System.Collections.Generic;15using System.Diagnostics;16using System.Linq;17using System.Text;18using System.Threading;19using System.Threading.Tasks;20using Telerik.JustMock;21using Telerik.JustMock.AutoMock;22namespace LexisNexis.Red.CommonTests.Business23{24 [TestFixture]25 public partial class PublicationUtilTest26 {27 [Test, Category("PublicationUtil_GetPublicationOffline")]28 public void GetPublicationOffline_Empty()29 {30 List<DlBook> dlBooks = new List<DlBook>();31 container.Arrange<IPublicationAccess>(publicationAccess => publicationAccess.GetDlBooksOffline( GlobalAccess.Instance.UserCredential)).Returns(dlBooks);32 var dlBookList = container.Instance.GetPublicationOffline();33 Assert.IsTrue(dlBookList.Count == 0);34 }35 [Test, Category("PublicationUtil_GetPublicationOffline")]36 public void GetPublicationOffline_OrderBy()37 {38 List<DlBook> dlBooks = new List<DlBook> { 39 new DlBook { BookId = 4, OrderBy = 1,RowId=1, ValidTo=DateTime.Now.AddDays(10).Date }, 40 new DlBook { BookId = 3, OrderBy = 7,RowId=2,ValidTo=DateTime.Now.AddDays(10).Date} ,41 new DlBook { BookId = 2, OrderBy = 6,RowId=3,ValidTo=DateTime.Now.AddDays(10).Date},42 new DlBook { BookId =9, OrderBy = 4,RowId=4,ValidTo=DateTime.Now.AddDays(10).Date } 43 };44 container.Arrange<IPublicationAccess>(publicationAccess => publicationAccess.GetDlBooksOffline(GlobalAccess.Instance.UserCredential)).IgnoreArguments().Returns(dlBooks);45 var dlBookList = container.Instance.GetPublicationOffline();46 Assert.IsTrue(dlBookList.FirstOrDefault().OrderBy == 1);47 Assert.IsTrue(dlBookList.LastOrDefault().OrderBy == 7);48 }49 [Test, Category("PublicationUtil_GetPublicationOffline")]50 public void GetPublicationOffline_RequireUpdate()51 {52 List<DlBook> dlBooks = new List<DlBook> { 53 new DlBook { BookId = 4, OrderBy = 1,DlStatus=(short)DlStatusEnum.Downloaded,LastDownloadedVersion=1,CurrentVersion=5,ValidTo=DateTime.Now.AddDays(10).Date }, 54 new DlBook { BookId = 3, OrderBy = 7,DlStatus=(short)DlStatusEnum.Downloaded,LastDownloadedVersion=2,CurrentVersion=5,ValidTo=DateTime.Now.AddDays(10).Date} ,55 new DlBook { BookId = 2, OrderBy = 6 ,DlStatus=(short)DlStatusEnum.Downloaded,LastDownloadedVersion=3,CurrentVersion=5,ValidTo=DateTime.Now.AddDays(10).Date},56 new DlBook { BookId =1, OrderBy = 4 ,DlStatus=(short)DlStatusEnum.Downloaded,LastDownloadedVersion=4,CurrentVersion=5,ValidTo=DateTime.Now.AddDays(10).Date} 57 };58 container.Arrange<IPublicationAccess>(publicationAccess => publicationAccess.GetDlBooksOffline( GlobalAccess.Instance.UserCredential)).Returns(dlBooks);59 var dlBookList = container.Instance.GetPublicationOffline();60 foreach (var item in dlBookList)61 {62 Assert.IsTrue(item.PublicationStatus == PublicationStatusEnum.RequireUpdate && item.UpdateCount == item.BookId);63 }64 }65 [Test, Category("PublicationUtil_GetPublicationOffline")]66 public void GetPublicationOffline_LoanOrTrialExpired()67 {68 List<DlBook> dlBooks = new List<DlBook> { 69 new DlBook { BookId = 4, IsLoan=true,ValidTo=DateTime.Now.AddDays(-5).Date}, 70 new DlBook { BookId = 2,IsTrial=true,ValidTo=DateTime.Now.AddDays(-5).Date},71 new DlBook { BookId =5,IsLoan=false,ValidTo=DateTime.Now.AddDays(-5).Date}72 };73 container.Arrange<IPublicationAccess>(publicationAccess => publicationAccess.GetDlBooksOffline( GlobalAccess.Instance.UserCredential)).IgnoreArguments().Returns(dlBooks);74 var dlBookList = container.Instance.GetPublicationOffline();75 var book4 = dlBookList.FirstOrDefault(o => o.BookId == 4);76 var book2 = dlBookList.FirstOrDefault(o => o.BookId == 2);77 var book5 = dlBookList.FirstOrDefault(o => o.BookId == 5);78 Assert.IsTrue(book4.DaysRemaining == 0);79 Assert.IsTrue(book2.DaysRemaining == 0);80 Assert.IsTrue(book5.DaysRemaining < 0);81 }82 [Test, Category("PublicationUtil_GetPublicationOffline")]83 public async void GetPublicationOffline_LocalDbDependency()84 {85 await LoginUtil.Instance.ValidateUserLogin(TestHelper.TestUsers[0].UserName, TestHelper.TestUsers[0].Password, TestHelper.TestUsers[0].CountryCode);86 var list = PublicationUtil.Instance.GetPublicationOffline();87 Assert.IsTrue(list == null || list.Count >= 0);88 }89 }90}...
Item
Using AI Code Generation
1Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);2Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);3Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);4Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);5Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);6Mock.Arrange(() => book[Arg.AnyInt]).Returns(0);
Item
Using AI Code Generation
1using Telerik.JustMock.Tests;2{3 public void TestMethod()4 {5 var book = Mock.Create<Book>();6 Mock.Arrange(() => book.Item[5]).Returns("test");7 var result = book.Item[5];8 Assert.AreEqual("test", result);9 }10}11using Telerik.JustMock.Tests;12{13 public void TestMethod()14 {15 var book = Mock.Create<Book>();16 Mock.Arrange(() => book.Item[5]).Returns("test");17 var result = book.Item[5];18 Assert.AreEqual("test", result);19 }20}21using Telerik.JustMock.Tests;22{23 public void TestMethod()24 {25 var book = Mock.Create<Book>();26 Mock.Arrange(() => book.Item[5]).Returns("test");27 var result = book.Item[5];28 Assert.AreEqual("test", result);29 }30}31using Telerik.JustMock.Tests;32{33 public void TestMethod()34 {35 var book = Mock.Create<Book>();36 Mock.Arrange(() => book.Item[5]).Returns("test");37 var result = book.Item[5];38 Assert.AreEqual("test", result);39 }40}41using Telerik.JustMock.Tests;42{43 public void TestMethod()44 {45 var book = Mock.Create<Book>();46 Mock.Arrange(() => book.Item[5]).Returns("test");47 var result = book.Item[5];48 Assert.AreEqual("test", result);49 }50}51using Telerik.JustMock.Tests;52{53 public void TestMethod()54 {55 var book = Mock.Create<Book>();56 Mock.Arrange(() => book.Item[5]).Returns("test");57 var result = book.Item[5];58 Assert.AreEqual("test", result);59 }60}
Item
Using AI Code Generation
1var book = Mock.Create<Book>();2Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");3Assert.AreEqual("hello", book.Item["test"]);4Assert.AreEqual("hello", book.Item["test2"]);5var book = Mock.Create<Book>();6Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");7Assert.AreEqual("hello", book.Item["test"]);8Assert.AreEqual("hello", book.Item["test2"]);9var book = Mock.Create<Book>();10Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");11Assert.AreEqual("hello", book.Item["test"]);12Assert.AreEqual("hello", book.Item["test2"]);13var book = Mock.Create<Book>();14Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");15Assert.AreEqual("hello", book.Item["test"]);16Assert.AreEqual("hello", book.Item["test2"]);17var book = Mock.Create<Book>();18Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");19Assert.AreEqual("hello", book.Item["test"]);20Assert.AreEqual("hello", book.Item["test2"]);21var book = Mock.Create<Book>();22Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");23Assert.AreEqual("hello", book.Item["test"]);24Assert.AreEqual("hello", book.Item["test2"]);25var book = Mock.Create<Book>();26Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");27Assert.AreEqual("hello", book.Item["test"]);28Assert.AreEqual("hello", book.Item["test2"]);29var book = Mock.Create<Book>();30Mock.Arrange(() => book.Item[Arg.AnyString]).Returns("hello");31Assert.AreEqual("hello",
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!