public void FillerWithSameObjectTest() { var f1 = new Foo { Id = 1, Name = "Silvio" }; var f2 = new Foo(); ObjectFiller<Foo, Foo>.Fill(f1, f2); var lf2 = new Likeness<Foo, Foo>(f2); Assert.AreEqual(lf2, f1); }
public void WithUnitPriceWillReturnCorrectResult() { // Fixture setup var fixture = new Fixture(); var sut = fixture.CreateAnonymous <EvaluatedProduct>(); var newUnitPrice = fixture.CreateAnonymous <Money>(); var expectedResult = new Likeness(new { sut.Id, sut.Name, UnitPrice = newUnitPrice }); // Exercise system EvaluatedProduct result = sut.WithUnitPrice(newUnitPrice); // Verify outcome Assert.AreEqual(expectedResult, result, "WithUnitPrice"); // Teardown }
public void ParseValidArgsWillReturnCorrectResult(decimal rate, Mock <Currency> currencyStub, [Frozen] Mock <CurrencyProvider> currencyProviderStub, CurrencyParser sut) { // Fixture setup var srcCurrencyArg = "EUR"; var destCurrencyArg = "USD"; var rateArg = rate.ToString(); currencyStub.Setup(c => c.Code).Returns(srcCurrencyArg); currencyProviderStub.Setup(cp => cp.GetCurrency(srcCurrencyArg)).Returns(currencyStub.Object); var expectedResult = new Likeness <CurrencyUpdateCommand, CurrencyUpdateCommand>(new CurrencyUpdateCommand(currencyStub.Object, destCurrencyArg, rate)); // Exercise system var result = sut.Parse(new[] { destCurrencyArg, srcCurrencyArg, rateArg }); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void ApplyDiscountForNormalCustomerWillReturnEquivalentProduct() { // Fixture setup var fixture = new Fixture(); var customerStub = new Mock<IPrincipal>(); customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(false); var product = fixture.CreateAnonymous<Product>(); var expectedResult = new Likeness<Product, Product>(product); var sut = fixture.CreateAnonymous<DefaultCustomerDiscountPolicy>(); // Exercise system Product result = sut.Apply(product, customerStub.Object); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void ThenTheFirstProjectCardContains(string title, string subtitle, string description, string summary, string met, string metKV, string partial, string partialKV, string notMet, string notMetKV) { ProjectCardModel actualModel = landingPage.GetCardDetails(); ProjectCardModel expectedModel = new ProjectCardModel(); expectedModel.Title = title; expectedModel.Subtitle = subtitle; expectedModel.Description = description; expectedModel.RequirementSummary = summary; expectedModel.ReqMet = met; expectedModel.ReqMetKV = metKV; expectedModel.ReqPartiallyMet = partial; expectedModel.ReqPartiallyMetKV = partialKV; expectedModel.ReqNotMet = notMet; expectedModel.ReqNotMetKV = notMetKV; var expectedModelLikeness = new Likeness <ProjectCardModel, ProjectCardModel>(expectedModel); expectedModelLikeness.ShouldEqual(actualModel); }
static void Main(string[] args) { Student st1 = new Student(); st1.ID = 20; st1.Name = "ligaoren"; Student st2 = new Student(); st2.ID = 20; st2.Name = "ligaoren"; var expectedStudent = new Likeness <Student, Student>(st1); Console.WriteLine(Equals(expectedStudent, st2)); Console.WriteLine(Equals(st1, st2)); Console.ReadLine(); }
public void ApplyDiscountForPreferredCustomerWillReturnCorrectlyDiscountedProduct() { // Fixture setup var fixture = new Fixture(); var customerStub = new Mock<IPrincipal>(); customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(true); var product = fixture.CreateAnonymous<Product>(); var expectedResult = new Likeness<Product, Product>(product) .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.Multiply(.95m).Equals(d.UnitPrice)); var sut = fixture.CreateAnonymous<DefaultCustomerDiscountPolicy>(); // Exercise system var result = sut.Apply(product, customerStub.Object); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void FindTest() { var actual = new PlayerDto { Id = will.Id, AspNetUser_Id = will.AspNetUser_Id, Name = will.Name }; var actualBG = new List <BoardGame>(); actualBG.Add(gloomHaven); actual.PlayersGames = actualBG; var LikenessBg = actual.AsSource().OfLikeness <PlayerDto>(); var SteralizedBG = new Likeness <PlayerDto, object>(actual); var results = p.Find(3) as JsonResult; Assert.AreEqual(SteralizedBG, results.Data); }
public void ApplyDiscountForNormalCustomerWillReturnEquivalentProduct() { // Fixture setup var fixture = new Fixture(); var customerStub = new Mock <IPrincipal>(); customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(false); var product = fixture.CreateAnonymous <Product>(); var expectedResult = new Likeness <Product, Product>(product); var sut = fixture.CreateAnonymous <DefaultCustomerDiscountPolicy>(); // Exercise system Product result = sut.Apply(product, customerStub.Object); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void SelfTest() { var actual = new PlayerDto { Id = 1, AspNetUser_Id = "eb218371-e5aa-4b18-9975-5197d242f130", Name = "Peter Jensen" }; var actualBG = new List <BoardGame>(); actualBG.Add(catan); actualBG.Add(bloodrage); actual.PlayersGames = actualBG; var LikenessBg = actual.AsSource().OfLikeness <PlayerDto>(); var SteralizedBG = new Likeness <PlayerDto, object>(actual); var results = p.Self() as JsonResult; Assert.AreEqual(SteralizedBG, results.Data); }
public void AddingGameToLibraryButExsistsAsBGTest() { boardgames.Clear(); boardgames.Add(bloodrage); boardgames.Add(catan); boardgames.Add(gloomHaven); boardgames.Add(williamsburg); libraries.Clear(); libraries.Add(lib1); libraries.Add(lib2); libraries.Add(lib3); var testBoardGames = new List <BoardGame>(); testBoardGames.Add(bloodrage); testBoardGames.Add(catan); testBoardGames.Add(gloomHaven); testBoardGames.Add(williamsburg); var newLibrary = new Library { AspNetUser = null, Id = 0, userId = "eb218371-e5aa-4b18-9975-5197d242f130", bgId = williamsburg.Id, favorite = null }; var TestLibrary = new List <Library>(); TestLibrary.Add(lib1); TestLibrary.Add(lib2); TestLibrary.Add(lib3); TestLibrary.Add(newLibrary); p.AddGameToLibrary(williamsburg); var testsLikeness = new Likeness <List <BoardGame>, List <BoardGame> >(testBoardGames); Assert.AreEqual(testBoardGames, boardgames); var newlibLikeness = new Likeness <Library, Library>(TestLibrary[3]); Assert.AreEqual(newlibLikeness, libraries[3]); libraries.Remove(newLibrary); }
public void ConvertToWillReturnConvertedItem() { // Fixture setup var fixture = new Fixture(); var currencyStub = new Mock <Currency>(); currencyStub.SetupGet(c => c.Code).Returns(fixture.CreateAnonymous("CurrencyCode")); currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny <string>())).Returns(2.7m); var item = fixture.CreateAnonymous <Product>(); var sut = fixture.Build <Extent>() .FromFactory(() => new Extent(item)) .OmitAutoProperties() .CreateAnonymous(); var expectedItem = new Likeness <Product, Product>(item.ConvertTo(currencyStub.Object)); // Exercise system var result = sut.ConvertTo(currencyStub.Object).Product; // Verify outcome Assert.True(expectedItem.Equals(result)); // Teardown }
public void SearchTest(string searchString, params string[] actual) { var result = ps.PlayerSearch(searchString) as JsonResult; var searchObject = result; var testList = new List <playerSearch>(); foreach (var name in actual) { foreach (var player in players) { if (player.Name == name) { var actualAsSearch = new playerSearch(player.Id, player.Name); testList.Add(actualAsSearch); } } } var SerchLikeness = new Likeness <List <playerSearch>, List <playerSearch> >(testList); Assert.AreEqual(SerchLikeness, result.Data); result = null; }
public void AddPlaySessionTest() { var playSession = new PlaySession(); playSession.Id = 22; playSession.BoardGame = catan; playSession.BoardGameId = 1; playSession.PlayTime = TimeSpan.Zero; var curr = DateTime.Now; playSession.DatePlayed = curr; var PlayerIds = new List <int>(); PlayerIds.Add(1); var results = ps.AddPlaySession(playSession, PlayerIds); //Assert.AreEqual(new HttpStatusCodeResult(HttpStatusCode.Accepted, "playsessionCreated"), results ); var finalPlaySession = new Likeness <PlaySession, PlaySession>(playSession); Assert.AreEqual(1, participants.Where(x => x.PlaySession_Id == 22).ToList().Count()); Assert.AreEqual(playsessions.FirstOrDefault(x => x.Id == 22), playSession); playsessions.Remove(playSession); }
public void ApplyDiscountForPreferredCustomerWillReturnCorrectlyDiscountedProduct() { // Fixture setup var fixture = new Fixture(); var customerStub = new Mock <IPrincipal>(); customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(true); var product = fixture.CreateAnonymous <Product>(); var expectedResult = new Likeness <Product, Product>(product) .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.Multiply(.95m).Equals(d.UnitPrice)); var sut = fixture.CreateAnonymous <DefaultCustomerDiscountPolicy>(); // Exercise system var result = sut.Apply(product, customerStub.Object); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public async Task GetLatestVersionPackageAsync_Should_Return_Latest_Version_Of_Package_When_Package_Correct() { string packageName = "NUnit"; nugetHttpServiceMock .Setup(nugetHttpService => nugetHttpService.GetPackageMetadataAsync(It.IsAny <string>())) .ReturnsAsync(await ResponsesReader.GetNUnitFromEndpointSearch()); PackageVersion packageVersion = await nugetApiService .GetLatestPackageVersionAsync(packageName); Likeness <PackageVersion, PackageVersion> expectedVersion = new Likeness <PackageVersion, PackageVersion>(packageVersion); Assert.AreEqual(expectedVersion, new PackageVersion { Major = 3, Minor = 11, Build = 0, Revision = -1 }); nugetHttpServiceMock.Verify(nugetHttpService => nugetHttpService.GetPackageMetadataAsync(packageName)); }
public static Likeness <TSource, TDestination> WithCollectionInnerSpecificLikeness <TSource, TDestination, TSourceProperty, TDestinationProperty, TSourcePropertySubType, TDestinationPropertySubType> ( this Likeness <TSource, TDestination> likeness, Expression <Func <TDestination, IEnumerable <TDestinationProperty> > > propertyPicker, Expression <Func <TSource, IEnumerable <TSourceProperty> > > sourcePropertyPicker, Func <Likeness <TSourcePropertySubType, TDestinationPropertySubType>, Likeness <TSourcePropertySubType, TDestinationPropertySubType> > likenessDefFunc = null ) where TSourcePropertySubType : class, TSourceProperty where TDestinationPropertySubType : class, TDestinationProperty where TSourceProperty : class where TDestinationProperty : class { return(likeness.With(propertyPicker) .EqualsWhen((s, d) => { DiagnosticsWriterLocator.DiagnosticsWriter.WriteMessage(String.Format("Comparing inner collections using likeness. Source: {0} Destination: {1}.", sourcePropertyPicker, propertyPicker)); var sourceCollection = ExpressionUtils.GetValue(sourcePropertyPicker, s); var destCollection = ExpressionUtils.GetValue(propertyPicker, d); return CompareUtils.CompareCollectionsUsingLikeness(likenessDefFunc, sourceCollection, destCollection); })); }
public static Likeness <TType, TType> WithCollectionSequenceEquals <TType>(this Likeness <TType, TType> likeness, Expression <Func <TType, IEnumerable> > propertyPicker) { return(likeness.WithCollectionSequenceEquals(propertyPicker, propertyPicker)); }
public void ConvertToWillReturnConvertedItem() { // Fixture setup var fixture = new Fixture(); var currencyStub = new Mock<Currency>(); currencyStub.SetupGet(c => c.Code).Returns(fixture.CreateAnonymous("CurrencyCode")); currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny<string>())).Returns(2.7m); var item = fixture.CreateAnonymous<Product>(); var sut = fixture.Build<Extent>() .FromFactory(() => new Extent(item)) .OmitAutoProperties() .CreateAnonymous(); var expectedItem = new Likeness<Product, Product>(item.ConvertTo(currencyStub.Object)); // Exercise system var result = sut.ConvertTo(currencyStub.Object).Product; // Verify outcome Assert.True(expectedItem.Equals(result)); // Teardown }
public void WithItemWillReturnCorrectExtent() { // Fixture setup var fixture = new Fixture(); var sut = fixture.CreateAnonymous<Extent>(); var newItem = fixture.CreateAnonymous<Product>(); var expectedResult = new Likeness<Extent, Extent>(new Extent(newItem) { Quantity = sut.Quantity, Updated = sut.Updated }).Without(d => d.Total); // Exercise system Extent result = sut.WithItem(newItem); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void WithUnitPriceWillReturnCorrectResult() { // Fixture setup var fixture = new Fixture(); var sut = fixture.CreateAnonymous<EvaluatedProduct>(); var newUnitPrice = fixture.CreateAnonymous<Money>(); var expectedResult = new Likeness(new { sut.Id, sut.Name, UnitPrice = newUnitPrice }); // Exercise system EvaluatedProduct result = sut.WithUnitPrice(newUnitPrice); // Verify outcome Assert.AreEqual(expectedResult, result, "WithUnitPrice"); // Teardown }
public static Likeness <T, NewMappingsEvent> WithoutProgrammaticIdentifier <T>(this Likeness <T, NewMappingsEvent> that) { return(that.Without(x => x.ProgrammaticIdentifier)); }
public void WithUnitPriceWillReturnCorrectResult() { // Fixture setup var fixture = new Fixture(); var sut = fixture.CreateAnonymous<Product>(); var newUnitPrice = fixture.CreateAnonymous<Money>(); var expectedResult = new Likeness<Product, Product>(new Product(sut.Id, sut.Name, newUnitPrice)); // Exercise system Product result = sut.WithUnitPrice(newUnitPrice); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void AnalyzePlayStats() { playsessions.Clear(); ps1.BoardGame = catan; playsessions.Add(ps1); participants.Clear(); participants.Add(par1); participants.Add(par2); players.Clear(); players.Add(peter); players.Add(will); List <playerSearch> newParticipants = new List <playerSearch>(); var playerSearch1 = new playerSearch(peter.Id, peter.Name); playerSearch1.Winner = true; playerSearch1.Team = 1; var playerSearch2 = new playerSearch(will.Id, will.Name); playerSearch2.Winner = true; playerSearch2.Team = 2; newParticipants.Add(playerSearch1); newParticipants.Add(playerSearch2); List <PlaySessionData> testPSD = new List <PlaySessionData>(); var sample = new PlaySessionData(catan, newParticipants, TimeSpan.Zero, new DateTime(2017, 11, 15, 9, 30, 00).ToString()); List <playerSearch> team1Members = new List <playerSearch>(); team1Members.Add(playerSearch1); var team1 = new Team(); team1.Name = 1; team1.Name = 1; team1.TeamMates = team1Members; team1.Winner = true; sample.Teams = new List <Team>(); sample.Teams.Add(team1); List <playerSearch> team2Members = new List <playerSearch>(); team2Members.Add(playerSearch2); var team2 = new Team(); team2.Name = 2; team2.TeamMates = team2Members; team2.Winner = false; sample.Teams.Add(team2); testPSD.Add(sample); var testlist = new List <PlayerStats>(); PlayerStats willstats = new PlayerStats(will.Id, will.Name); willstats.Plays = 1; //willstats.Wins = 1; willstats.OpponentWin = 1; testlist.Add(willstats); var results = StatsCtrl.AnalyzePlayStats(testPSD, playerSearch1); var testlistlikeness = new Likeness <List <PlayerStats>, List <PlayerStats> >(testlist); //Assert.AreEqual(results.AshamedLosers, new List<PlayerStats>()); //Assert.AreEqual(results.CourageousAllies, new List<PlayerStats>()); //Assert.AreEqual(results.FrailAllies, new List<PlayerStats>()); //Assert.AreEqual(results.TieGuys, new List<PlayerStats>()); //Assert.AreEqual(results.Conqueror, new List<PlayerStats>()); //Assert.AreEqual(results.DastardlyVillan, new List<PlayerStats>()); //Assert.AreEqual( testlistlikeness, results.Buddies); //Assert.AreEqual(testlistlikeness, results.CowardlyVillan); //Assert.AreEqual(testlistlikeness, results.Fodder); }
public void ParseValidArgsWillReturnCorrectResult(decimal rate, Mock<Currency> currencyStub, [Frozen]Mock<CurrencyProvider> currencyProviderStub, CurrencyParser sut) { // Fixture setup var srcCurrencyArg = "EUR"; var destCurrencyArg = "USD"; var rateArg = rate.ToString(); currencyStub.Setup(c => c.Code).Returns(srcCurrencyArg); currencyProviderStub.Setup(cp => cp.GetCurrency(srcCurrencyArg)).Returns(currencyStub.Object); var expectedResult = new Likeness<CurrencyUpdateCommand, CurrencyUpdateCommand>(new CurrencyUpdateCommand(currencyStub.Object, destCurrencyArg, rate)); // Exercise system var result = sut.Parse(new[] { destCurrencyArg, srcCurrencyArg, rateArg }); // Verify outcome Assert.True(expectedResult.Equals(result)); // Teardown }
public void ParseValidArgsWillReturnCorrectResult() { // Fixture setup var fixture = new CurrencyFixture(); var rate = fixture.CreateAnonymous<decimal>(); var srcCurrencyArg = "EUR"; var destCurrencyArg = "USD"; var rateArg = rate.ToString(); var currencyStub = fixture.CreateMoq<Currency>(); currencyStub.Setup(c => c.Code).Returns(srcCurrencyArg); fixture.FreezeMoq<CurrencyProvider>().Setup(cp => cp.GetCurrency(srcCurrencyArg)).Returns(currencyStub.Object); var expectedResult = new Likeness<CurrencyUpdateCommand, CurrencyUpdateCommand>(new CurrencyUpdateCommand(currencyStub.Object, destCurrencyArg, rate)); var sut = fixture.CreateAnonymous<CurrencyParser>(); // Exercise system var result = sut.Parse(new[] { destCurrencyArg, srcCurrencyArg, rateArg }); // Verify outcome Assert.AreEqual(expectedResult, result, "Parse"); // Teardown }
public void ConvertWillReturnCorrectResult() { // Fixture setup var fixture = new CurrencyFixture(); var currency = fixture.CreateAnonymous<Currency>(); var sut = fixture.CreateAnonymous<EvaluatedProduct>(); var expectedProduct = new Likeness(sut.WithUnitPrice(sut.UnitPrice.ConvertTo(currency))); // Exercise system EvaluatedProduct result = sut.ConvertTo(currency); // Verify outcome Assert.AreEqual(expectedProduct, result, "ConvertTo"); // Teardown }