public void ChangeAssessorTests_ChangeTypeChanged_NoChangesShouldBePresentedAsThisFieldIsIgnored()
        {
            //Note I am using sub properties to ensure the name is ignored in both levels of different types
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("23145");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            //Ensure statuses are different
            source.ChangeType      = ChangeType.Updated;
            destination.ChangeType = ChangeType.Added;

            source.B.ChangeType      = ChangeType.None;
            destination.B.ChangeType = ChangeType.Deleted;


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
Exemple #2
0
        public void ChangeAssessorTests_SubPropertyValuesIdDifferent_SubPropertySetWithAnAddAndARemove()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Different ids
            source.B         = MockDataHelper.BuildMultiLevelB("1");
            destination.B    = Mapper.Map <MultiLevelB>(source.B);
            destination.B.Id = "SOmething different";

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(0, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            Assert.AreEqual(2, assessment.Relationships.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            var relationshipDeleted = assessment.Relationships.FirstOrDefault(f => f.Value == destination.B);

            Assert.IsNotNull(relationshipDeleted, "Destination should be in the list of changed relationships");
            Assert.AreEqual(relationshipDeleted.Parent, source, "Proper parent should be assigned in the relationship ");
            Assert.AreEqual(relationshipDeleted.ChangeType, ChangeType.Deleted, "Change Type is set to Added ");


            var relationshipAdded = assessment.Relationships.FirstOrDefault(f => f.Value == source.B);

            Assert.IsNotNull(relationshipAdded, "Destination should be in the list of changed relationships");
            Assert.AreEqual(relationshipAdded.Parent, source, "Proper parent should be assigned in the relationship ");
            Assert.AreEqual(relationshipAdded.ChangeType, ChangeType.Added, "Change Type is set to Added ");
        }
        public void ChangeAssessorTests_IgnoreFieldNameSet_ChangesAreNotDetectedForFieldsSet()
        {
            //Note I am using sub properties to ensure the name is ignored in both levels of different types
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("23145");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            //Change  StringField, and Int32
            source.StringField   = Guid.NewGuid().ToString();
            source.Int32Field   += 2000;
            source.B.StringField = Guid.NewGuid().ToString();
            source.B.Int32Field += 1000;

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Ignoring both fields
                                                     .IgnoreFields("StringField", "Int32Field");

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
        public void ChangeAssessorTests_SubPropertyRemoved_IsOwner_SubPropertySetAsRemoved()
        {
            var source      = MockDataHelper.BuildMultiLevelA("1");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Note source will now have a sub single property
            //This is removed and not in the source
            destination.B = MockDataHelper.BuildMultiLevelB("23145");

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ownership assignment
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B);

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(destination.B, assessment.OwnedEntities[0], "Destination record returned as Deleted");
            Assert.AreEqual(ChangeType.Deleted, destination.B.ChangeType, "Change Type is set to Deleted");

            //Relationships
            Assert.AreEqual(assessment.Relationships.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));

            var relationship = assessment.Relationships.FirstOrDefault(r => r.Value == destination.B);

            Assert.IsNotNull(relationship, "Record {0} should be in the list of changed relationships");
            Assert.AreEqual(relationship.Parent, source, "Proper parent should be assigned in the relationship");
            Assert.AreEqual(relationship.ChangeType, ChangeType.Deleted, "Change Type is set to Deleted");
        }
Exemple #5
0
        public void CreateModuloTest()
        {
            var modulo    = MockDataHelper.Modulos.FirstOrDefault();
            var plantilla = MockDataHelper.Plantillas.FirstOrDefault();
            var categoria = MockDataHelper.Categorias.FirstOrDefault();

            var empresas = iSeguridadService.GetProfesionales("nico", 10);

            modulo.Codigo       = 0;
            plantilla.Codigo    = 0;
            categoria.Codigo    = 0;
            categoria.IdEmpresa = 9;

            var idcategoria = this.iCategoriaService.CreateOrUpdateCategoria(1884, categoria);

            plantilla.IdCategoria = idcategoria;
            plantilla.Ambitos     = MockDataHelper.GetListAmbito();

            var idPlantilla = this.iPlantillaService.CreateOrUpdatePlantilla(1884, plantilla);

            modulo.IdPlantilla = idPlantilla;

            var idModulo = this.iModuloService.CreateOrUpdateModulo(1884, modulo);

            Assert.IsTrue(idModulo > 0);
        }
Exemple #6
0
        public void ChangeAssessorTests_List_RootValuesAdded_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };
            //Note out of order to ensure test covers other scenarios
            var destination = new List <OneLevel>()
            {
                source[2]
            };
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatusList(source, destination);


            var expectedIndices = new[] { 0, 1, 3 };


            Assert.AreEqual(expectedIndices.Length, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            foreach (var expectedIndex in expectedIndices)
            {
                Assert.IsTrue(assessment.OwnedEntities.Contains(source[expectedIndex]), string.Format("Record {0} should be in the list of changes", expectedIndex));
                Assert.AreEqual(ChangeType.Added, source[expectedIndex].ChangeType, string.Format("Record {0} should have the added change type", expectedIndex));
            }
        }
Exemple #7
0
        public void ChangeAssessorTests_SubListPropertyValuesChanged_IsOwner_SubListPropertySetAsUpdated()
        {
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.Cs = new System.Collections.Generic.List <MultiLevelC>()
            {
                MockDataHelper.BuildMultiLevelC("11"),
                MockDataHelper.BuildMultiLevelC("22")
            };
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.Cs = source.Cs.Select(c => Mapper.Map <MultiLevelC>(c)).ToList();
            destination.Cs[0].StringField = "I am different1";
            destination.Cs[1].StringField = "I am different2";

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ownership
                                                     .AddOwnerMapping <MultiLevelA>(a => a.Cs);

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 2, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[0]), "Cs 0 returned as changed");
            Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[1]), "Cs 1 returned as changed");
            Assert.AreEqual(source.Cs[0].ChangeType, ChangeType.Updated, "Change Type is set to updated for C 0");
            Assert.AreEqual(source.Cs[1].ChangeType, ChangeType.Updated, "Change Type is set to updated for C 1");
        }
Exemple #8
0
        public void ChangeAssessorTests_SubPropertyAdded_IsOwner_SubPropertySetAsAdded()
        {
            var source      = MockDataHelper.BuildMultiLevelA("1");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Note source will now have a sub single property
            //This is new and not in the destiation
            source.B = MockDataHelper.BuildMultiLevelB("23145");


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note owner addition
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B)
            ;

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B, assessment.OwnedEntities[0], "Source record returned as Added");
            Assert.AreEqual(source.B.ChangeType, ChangeType.Added, "Change Type is set to Added");

            //relationships
            Assert.AreEqual(assessment.Relationships.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B, assessment.Relationships[0].Value, "Source record returned as in relationship changes");
            Assert.AreEqual(assessment.Relationships[0].Parent, source, "Proper parent should be assigned in the relationship");
            Assert.AreEqual(assessment.Relationships[0].ChangeType, ChangeType.Added, "Change Type is set to Added");
        }
Exemple #9
0
        public async Task GetMovie_200(string movieId, MovieEntity expectedMovie)
        {
            // Arrange
            var expectedResult   = Mapper.Map <MovieEntity, GetMovieResponse>(expectedMovie);
            var mockMovieService = new Mock <IMovieService>();

            mockMovieService.Setup(x => x.GetOne(It.IsAny <string>()))
            .Returns((string mId) => Task.FromResult(MockDataHelper.GetMovie(mId)));
            // Act
            var movieController = new MovieController(Mapper, mockMovieService.Object);
            var response        = await movieController.GetMovieMetaInfo(movieId);

            // Assert
            var okResponse = Assert.IsType <OkObjectResult>(response.Result);
            var result     = Assert.IsAssignableFrom <GetMovieResponse>(okResponse.Value);

            Assert.Equal(expectedResult.Id, result.Id);
            Assert.Equal(expectedResult.Title, result.Title);
            Assert.Equal(expectedResult.PlotSummary, result.PlotSummary);
            Assert.Equal(expectedResult.Director, result.Director);
            Assert.Equal(expectedResult.Tags, result.Tags);
            Assert.Equal(expectedResult.ReleaseDate, result.ReleaseDate);
            Assert.Equal(expectedResult.Language, result.Language);
            Assert.Equal(expectedResult.CountReviews, result.CountReviews);
            Assert.Equal(expectedResult.Rating, result.Rating);
        }
Exemple #10
0
        public void ChangeAssessorTests_List_RootValuesNoChangeAndOutOfOrder_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };
            //Note out of order to ensure test covers other scenarios
            var destination = new List <OneLevel>()
            {
                Mapper.Map <OneLevel>(source[2]),
                Mapper.Map <OneLevel>(source[1]),
                Mapper.Map <OneLevel>(source[0]),
                Mapper.Map <OneLevel>(source[3])
            };


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatusList(source, destination);



            Assert.AreEqual(0, assessment.OwnedEntities.Count, string.Format("No changes expected, received {0}", assessment.OwnedEntities.Count));

            foreach (var sourceItem in source)
            {
                Assert.AreEqual(ChangeType.None, sourceItem.ChangeType, string.Format("Record {0} should have the none change type", sourceItem.Id));
            }
        }
Exemple #11
0
        public void ChangeAssessorTests_SubListPropertyValuesAddDeletedAndUpdated_IsOwner_SubListPropertySetAsMixedStatuses()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            source.B      = MockDataHelper.BuildMultiLevelB("5523");
            destination.B = MockDataHelper.BuildMultiLevelB("5523");
            //The root is changed as well
            destination.StringField = Guid.NewGuid().ToString();


            //Note out of order to ensure test covers other scenarios
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ownership
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B);

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(2, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source), "Root record should be in the list of changes");
            Assert.AreEqual(ChangeType.Updated, source.ChangeType, string.Format("Record {0} should have the update change type", 2));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source.B), "Sub record should be in the list of changes");
            Assert.AreEqual(ChangeType.Updated, source.B.ChangeType, string.Format("Record {0} should have the update change type", 2));
        }
Exemple #12
0
        public void ChangeAssessorTests_ListDestinationNull_RootValuesAdded_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };

            //note null
            List <OneLevel>         destination    = null;
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatusList(source, destination);


            var expectedIndices = Enumerable.Range(0, source.Count);


            Assert.AreEqual(expectedIndices.Count(), assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            foreach (var expectedIndex in expectedIndices)
            {
                Assert.IsTrue(assessment.OwnedEntities.Contains(source[expectedIndex]), string.Format("Record {0} should be in the list of changes", expectedIndex));
                Assert.AreEqual(ChangeType.Added, source[expectedIndex].ChangeType, string.Format("Record {0} should have the added change type", expectedIndex));
            }
        }
Exemple #13
0
        public void Test2()
        {
            var mockData = MockDataHelper.GetInvoiceData();

            InvoiceDataStore.Add(mockData);
            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            Assert.That(_invoiceStore[mockData.InvoiceNo].TotalAmount == mockData.TotalAmount);
        }
Exemple #14
0
        public void ChangeAssessorTests_List_SubPropertyValuesAddDeletedAndUpdatedAndRootUpdated_SubPropertySetAsMixedStatuses()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            source.Cs = new List <MultiLevelC>()
            {
                MockDataHelper.BuildMultiLevelC("-2124"), MockDataHelper.BuildMultiLevelC("1"), MockDataHelper.BuildMultiLevelC("5212")
            };
            destination.Cs = new List <MultiLevelC>()
            {
                //Existing, unchanged
                Mapper.Map <MultiLevelC>(source.Cs[0]),
                //To Be updated
                MockDataHelper.BuildMultiLevelC("1"),
                //Note index 2 is not here and therefore added

                //Does not exist in source and therefore will be deleted
                MockDataHelper.BuildMultiLevelC("14wdwedqweqe")
            };

            //The root is changed as well
            destination.StringField = Guid.NewGuid().ToString();


            //Note out of order to ensure test covers other scenarios
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(1, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(2, assessment.Relationships.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));


            Assert.IsTrue(assessment.OwnedEntities.Contains(source), "Root record should be in the list of changes");
            Assert.AreEqual(ChangeType.Updated, source.ChangeType, string.Format("Record {0} should have the update change type", 2));

            Assert.AreEqual(ChangeType.None, source.Cs[0].ChangeType, string.Format("Record {0} should have the none change type", 0));

            Assert.AreEqual(ChangeType.None, source.Cs[1].ChangeType, string.Format("Record {0} should have the none change type as it is not owned", 1));


            var relationshipS2 = assessment.Relationships.FirstOrDefault(r => r.Value == source.Cs[2]);

            Assert.IsNotNull(relationshipS2, "Record 2 should be in the list of changed relationships S2");
            Assert.AreEqual(relationshipS2.Parent, source, "Proper parent should be assigned in the relationship S2");
            Assert.AreEqual(relationshipS2.ChangeType, ChangeType.Added, "Change Type is set to Added S2");
            Assert.AreEqual(source.Cs[2].ChangeType, ChangeType.None, "Actual Entity type not changed due to lack of ownership S2");


            var relationshipD2 = assessment.Relationships.FirstOrDefault(r => r.Value == destination.Cs[2]);

            Assert.IsNotNull(relationshipD2, "Record 2 should be in the list of changed relationships D2");
            Assert.AreEqual(relationshipD2.Parent, source, "Proper parent should be assigned in the relationship D2");
            Assert.AreEqual(relationshipD2.ChangeType, ChangeType.Deleted, "Change Type is set to Deleted D2");
            Assert.AreEqual(destination.Cs[2].ChangeType, ChangeType.None, "Actual Entity type not changed due to lack of ownership D2");
        }
Exemple #15
0
        public async Task GetRecentReviews_200(string userName, int maxItems, MovieReviewDto expectedReviews)
        {
            // Arrange
            // Arrange
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, userName),
            }, "mock"));

            var expectedResult    = Mapper.Map <MovieReviewDto, GetRecentReviewsResponse>(expectedReviews);
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.GetRecentReviewsFromFollowedAsync(It.IsAny <string>(), It.IsAny <int>()))
            .Returns((string mId, int maxItems) => {
                var reviews = MockDataHelper.GetReviews(mId);
                return(Task.FromResult(new MovieReviewDto
                {
                    Reviews = reviews.Reviews.Take(maxItems)
                }));
            });
            // Act
            var reviewController = new ReviewController(Mapper, mockReviewService.Object);
            var request          = new GetRecentReviewsRequest
            {
                NumberOfItems = 10
            };

            reviewController.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };
            MockModelState(request, reviewController);


            var response = await reviewController.GetRecentReviews(request);

            // Assert
            var okResponse = Assert.IsType <OkObjectResult>(response.Result);
            var result     = Assert.IsAssignableFrom <GetRecentReviewsResponse>(okResponse.Value);

            Assert.True(maxItems >= result.Reviews.Count());
            foreach (var(actualReview, expectedReview) in result.Reviews.Zip(expectedResult.Reviews))
            {
                Assert.Equal(expectedReview.Author.DisplayName, actualReview.Author.DisplayName);
                Assert.Equal(expectedReview.Author.UserName, actualReview.Author.UserName);
                Assert.Equal(expectedReview.Author.Followers, actualReview.Author.Followers);
                Assert.Equal(expectedReview.Author.Id, actualReview.Author.Id);

                Assert.Equal(expectedReview.Description, actualReview.Description);
                Assert.Equal(expectedReview.Rating, actualReview.Rating);
                Assert.Equal(expectedReview.Title, actualReview.Title);

                Assert.Equal(expectedReview.Movie.Id, actualReview.Movie.Id);
                Assert.Equal(expectedReview.Movie.Title, actualReview.Movie.Title);
            }
        }
Exemple #16
0
        public void Test5()
        {
            var mockData = MockDataHelper.GetInvoiceData();

            InvoiceDataStore.Update(mockData.InvoiceNo, mockData);
            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            Assert.That(_invoiceStore[mockData.InvoiceNo].Status == Status.NotProcessed);
            InvoiceDataStore.UpdateStatus(mockData.InvoiceNo, Status.Digitized);
            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            Assert.That(_invoiceStore[mockData.InvoiceNo].Status == Status.Digitized);
        }
        public ActionResult News()
        {
            NewsModel news = new NewsModel();
            int       day  = DateTime.Now.Day;

            if (day == 15 || day == 30)
            {
                MockDataHelper.UpdateNewsMockData();
            }
            news = GetDataHelper.GetNews();
            return(View(news));
        }
Exemple #18
0
        public void ChangeAssessorTests_RootValuesChanged_RootSetAsNoChange()
        {
            //Note both should be randomly generated but have the same ID
            var source      = MockDataHelper.BuildOneLevel("1");
            var destination = Mapper.Map <OneLevel>(source);
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 0, string.Format("No changes expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.ChangeType, ChangeType.None, "Change Type is set to NoChange");
        }
Exemple #19
0
        public void Test1()
        {
            var mockData = MockDataHelper.GetInvoiceData();

            Assert.That(!string.IsNullOrEmpty(mockData.InvoiceNo));
            Assert.That(mockData.InvoiceDate != null);
            Assert.That(mockData.Seller != null && !string.IsNullOrEmpty(mockData.Seller.Name));
            Assert.That(mockData.BillTo != null && !string.IsNullOrEmpty(mockData.BillTo.Name));
            Assert.That(mockData.ShipTo != null && !string.IsNullOrEmpty(mockData.ShipTo.Name));
            Assert.That(mockData.Items != null && mockData.Items.Count() > 0);
            Assert.That(mockData.SubTotal != 0);
            Assert.That(mockData.TotalAmount != 0);
        }
Exemple #20
0
        public void Test3()
        {
            var mockData = MockDataHelper.GetInvoiceData();

            InvoiceDataStore.Add(mockData);
            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            mockData.Seller.Name    = "Zomato";
            mockData.ShipTo.ZipCode = "234323";
            InvoiceDataStore.Update(mockData.InvoiceNo, mockData);
            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            Assert.That(_invoiceStore[mockData.InvoiceNo].Seller.Name.Equals("Zomato"));
            Assert.That(_invoiceStore[mockData.InvoiceNo].ShipTo.ZipCode.Equals("234323"));
        }
Exemple #21
0
        public async Task GetMovie_400(string movieId)
        {
            // Arrange
            var mockMovieService = new Mock <IMovieService>();

            mockMovieService.Setup(x => x.GetOne(It.IsAny <string>()))
            .Returns((string mId) => Task.FromResult(MockDataHelper.GetMovie(mId)));
            // Act
            var movieController = new MovieController(Mapper, mockMovieService.Object);
            var response        = await movieController.GetMovieMetaInfo(movieId);

            // Assert
            var badRequest = Assert.IsType <BadRequestObjectResult>(response.Result);
        }
Exemple #22
0
        public void ChangeAssessorTests_RootValuesChanged_RootSetAsUpdated()
        {
            //Note both should be randomly generated but have the same ID
            var source      = MockDataHelper.BuildOneLevel("1");
            var destination = MockDataHelper.BuildOneLevel("1");
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities));
            Assert.AreEqual(source, assessment.OwnedEntities[0], "Source record returned as changed");
            Assert.AreEqual(source.ChangeType, ChangeType.Updated, "Change Type is set to updated");
        }
Exemple #23
0
        public void ChangeAssessorTests_List_SubPropertyValuesAddDeletedAndUpdatedAndRootUpdated_IsOwner_SubPropertySetAsMixedStatuses()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            source.Cs = new List <MultiLevelC>()
            {
                MockDataHelper.BuildMultiLevelC("-2124"), MockDataHelper.BuildMultiLevelC("1"), MockDataHelper.BuildMultiLevelC("5212")
            };
            destination.Cs = new List <MultiLevelC>()
            {
                //Existing, unchanged
                Mapper.Map <MultiLevelC>(source.Cs[0]),
                //To Be updated
                MockDataHelper.BuildMultiLevelC("1"),
                //Note index 2 is not here and therefore added

                //Does not exist in source and therefore will be deleted
                MockDataHelper.BuildMultiLevelC("14wdwedqweqe")
            };

            //The root is changed as well
            destination.StringField = Guid.NewGuid().ToString();


            //Note out of order to ensure test covers other scenarios
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Adding Ownershio
                                                     .AddOwnerMapping <MultiLevelA>(c => c.Cs);

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(4, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source), "Root record should be in the list of changes");
            Assert.AreEqual(ChangeType.Updated, source.ChangeType, string.Format("Record {0} should have the update change type", 2));

            Assert.AreEqual(ChangeType.None, source.Cs[0].ChangeType, string.Format("Record {0} should have the none change type", 0));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[1]), string.Format("Record {0} should be in the list of changes", 1));
            Assert.AreEqual(ChangeType.Updated, source.Cs[1].ChangeType, string.Format("Record {0} should have the updated change type", 1));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[2]), string.Format("Record {0} should be in the list of changes", 2));
            Assert.AreEqual(ChangeType.Added, source.Cs[2].ChangeType, string.Format("Record {0} should have the added change type", 2));

            Assert.IsTrue(assessment.OwnedEntities.Contains(destination.Cs[2]), string.Format("Record {0} should be in the list of changes", 2));
            Assert.AreEqual(ChangeType.Deleted, destination.Cs[2].ChangeType, string.Format("Record {0} should have the removed change type", 2));
        }
 /// <summary>
 /// Parsing the invoice file and extract and stores the data
 /// Actual Parsing Need to be implemented
 /// </summary>
 /// <param name="filePath"> Invoice file path</param>
 /// <returns></returns>
 public bool ProcessInvoice(IEnumerable <string> invoiceFiles)
 {
     try {
         foreach (var file in invoiceFiles)
         {
             var data = MockDataHelper.GetInvoiceData();
             data.Status = Status.Digitized;
             InvoiceDataStore.Add(data);
         }
         return(true);
     }
     catch (Exception) {
         return(false);
     }
 }
Exemple #25
0
        public void ChangeAssessorTests_SubListPropertyValuessAdded_IsOwner_SubListPropertySetAsAdded()
        {
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.Cs = new System.Collections.Generic.List <MultiLevelC>()
            {
                MockDataHelper.BuildMultiLevelC("00"),
                MockDataHelper.BuildMultiLevelC("11"),
                MockDataHelper.BuildMultiLevelC("22")
            };
            var destination = Mapper.Map <MultiLevelA>(source);

            //Note only one exists therefore 2 should be added
            destination.Cs = new List <MultiLevelC>()
            {
                Mapper.Map <MultiLevelC>(source.Cs[1])
            };

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ownership
                                                     .AddOwnerMapping <MultiLevelA>(a => a.Cs);

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            var expectedIndices = new[] { 0, 2 };

            Assert.AreEqual(expectedIndices.Length, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            foreach (var expectedIndex in expectedIndices)
            {
                Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[expectedIndex]), string.Format("Record {0} should be in the list of changes", expectedIndex));
                Assert.AreEqual(ChangeType.Added, source.Cs[expectedIndex].ChangeType, string.Format("Record {0} should have the added change type", expectedIndex));
            }

            //Relationships
            Assert.AreEqual(expectedIndices.Length, assessment.Relationships.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));

            foreach (var expectedIndex in expectedIndices)
            {
                var relationship = assessment.Relationships.FirstOrDefault(r => r.Value == source.Cs[expectedIndex]);

                Assert.IsNotNull(relationship, string.Format("Record {0} should be in the list of changed relationships", expectedIndex));
                Assert.AreEqual(relationship.Parent, source, "Proper parent should be assigned in the relationship " + expectedIndex);
                Assert.AreEqual(relationship.ChangeType, ChangeType.Added, "Change Type is set to Added " + expectedIndex);
            }
        }
        public void GetAgrupadorUnitTest()
        {
            var agrupador1 = MockDataHelper.Agrupadores.FirstOrDefault();

            var modulo    = MockDataHelper.Modulos.FirstOrDefault();
            var plantilla = MockDataHelper.Plantillas.FirstOrDefault();
            var categoria = MockDataHelper.Categorias.FirstOrDefault();

            categoria.Codigo    = 0;
            categoria.IdEmpresa = 11;
            categoria.Vigencia  = Vigencia.NoVigente;

            plantilla.Codigo   = 0;
            plantilla.Vigencia = Vigencia.NoVigente;

            modulo.Codigo   = 0;
            modulo.Vigencia = Vigencia.NoVigente;

            var idcategoria = this.iCategoriaService.CreateOrUpdateCategoria(11, categoria);

            plantilla.IdCategoria = idcategoria;
            plantilla.Ambitos     = MockDataHelper.GetListAmbito();

            var idPlantilla = this.iPlantillaService.CreateOrUpdatePlantilla(11, plantilla);

            modulo.IdPlantilla = idPlantilla;

            var idModulo = this.iModuloService.CreateOrUpdateModulo(11, modulo);

            agrupador1.Codigo   = 0;
            agrupador1.IdModulo = idModulo;

            var id = this.iAgrupadorService.CreateOrUpdateAgrupador(11, agrupador1);

            Assert.IsTrue(id > 0);

            var agrupador2 = this.iAgrupadorService.GetAgrupador(id);

            Assert.IsTrue(agrupador1.AlineacionAyuda == agrupador2.AlineacionAyuda);
            Assert.IsTrue(agrupador1.IdModulo == agrupador2.IdModulo);
            Assert.IsTrue(agrupador1.Nombre == agrupador2.Nombre);
            Assert.IsTrue(agrupador1.IsNombreVisible == agrupador2.IsNombreVisible);
            Assert.IsTrue(agrupador1.Orden == agrupador2.Orden);
            Assert.IsTrue(agrupador1.TextoAyuda == agrupador2.TextoAyuda);
            Assert.IsTrue(agrupador1.Vigencia == agrupador2.Vigencia);
        }
        public void AutoMapper_ConvertFrom_AcceptedRequest_IsValid()
        {
            var entity          = MockDataHelper.GetAcceptedRequestMock();
            var acceptedRequest = new AcceptedRequestMappingProfile();
            var mapperConfig    = new MapperConfiguration(m =>
            {
                m.AddProfile(acceptedRequest);
            });

            mapperConfig.AssertConfigurationIsValid();

            var mapper = new Mapper(mapperConfig);
            var dto    = mapper.Map <AcceptedRequestDto>(entity);

            Assert.IsNotNull(dto);
            Assert.IsInstanceOf <AcceptedRequestDto>(dto);
            Assert.IsTrue(dto.RequestId == entity.RequestId);
        }
        public void ChangeAssessorTests_IgnoreBaseClassSet_ChangesAreNotDetectedForBaseClassFields()
        {
            var source      = MockDataHelper.BuildMultiLevelC("1");
            var destination = Mapper.Map <MultiLevelC>(source);
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ignoring the whole class
                                                     .IgnoreFields <BaseClassToIgnore>()
            ;
            //Only change fields from ignored class cast for test safety
            var sourceCastToBaseClass = (BaseClassToIgnore)source;

            sourceCastToBaseClass.StringField = Guid.NewGuid().ToString();


            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
Exemple #29
0
        public void Test4()
        {
            var mockData = MockDataHelper.GetInvoiceData();

            InvoiceDataStore.Add(mockData);
            var oldInvoiceNo = mockData.InvoiceNo;
            var newInvoiceNo = Guid.NewGuid().ToString();

            Assert.That(_invoiceStore.ContainsKey(mockData.InvoiceNo));
            mockData.InvoiceNo      = newInvoiceNo;
            mockData.Seller.Name    = "Zomato";
            mockData.ShipTo.ZipCode = "234323";
            InvoiceDataStore.Update(mockData.InvoiceNo, mockData);
            Assert.That(_invoiceStore.ContainsKey(newInvoiceNo));
            Assert.That(_invoiceStore[newInvoiceNo].Seller.Name.Equals("Zomato"));
            Assert.That(_invoiceStore[newInvoiceNo].ShipTo.ZipCode.Equals("234323"));
            Assert.That(_invoiceStore.ContainsKey(oldInvoiceNo));
        }
Exemple #30
0
        public void ChangeAssessorTests_SubPropertyValuesChanged_SubPropertySetAsNoChange()
        {
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("2");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 0, string.Format("No changes expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B.ChangeType, ChangeType.None, "Change Type is set to None");
        }