コード例 #1
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldReturnCreatedListWithAnalysesWhenJSONHaveCorrectTypes()
        {
            Mock <IAnalysis>           analysisMock           = new Mock <IAnalysis>();
            Mock <IAnalysisSetFactory> analysisSetFactoryMock = new Mock <IAnalysisSetFactory>();

            Mock <IAnalysisSet> analysisSetMock = new Mock <IAnalysisSet>();

            analysisSetMock.Setup(m => m.ConfiguredAnalyses).Returns(new List <IAnalysis>()
            {
                analysisMock.Object
            });
            analysisSetMock.Setup(m => m.Name).Returns("SETNAME");

            analysisSetFactoryMock.Setup(m => m.CreateInstance(It.IsAny <string>(), It.IsAny <IEnumerable <IAnalysis> >())).Returns(analysisSetMock.Object);

            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();

            AnalysisSetJSONFactory analysisSetJSONFactory = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);
            List <IAnalysisSet>    listOfCreatedSets      = new List <IAnalysisSet>(analysisSetJSONFactory.CreateInstance("{'configuration':[{'type':'analysisset','name':'name1','analyses':[{},{}]},{'type':'analysisset','name':'name2','analyses':[{},{}]}]}"));

            Assert.AreEqual(listOfCreatedSets.Count, 2);
            foreach (var item in listOfCreatedSets)
            {
                Assert.AreEqual(item, analysisSetMock.Object);
                List <IAnalysis> analises = new List <IAnalysis>(item.ConfiguredAnalyses);
                foreach (var analysis in analises)
                {
                    Assert.AreEqual(analysis, analysisMock.Object);
                }
            }
        }
コード例 #2
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONHaveConfigurationWithChildObjectsWithoutType()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            analysisSetJSONFactory.CreateInstance("{'configuration':[{},{}]}");
        }
コード例 #3
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONHaveConfigurationButIsNotAnList()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            analysisSetJSONFactory.CreateInstance("{'configuration':{}}");
        }
コード例 #4
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONisInvalid()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            analysisSetJSONFactory.CreateInstance("{");
        }
コード例 #5
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONStringIsEmpty()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            analysisSetJSONFactory.CreateInstance(string.Empty);
        }
コード例 #6
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONHaveCorrectTypesButWithoutName()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();

            AnalysisSetJSONFactory analysisSetJSONFactory = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);
            List <IAnalysisSet>    listOfCreatedSets      = new List <IAnalysisSet>(analysisSetJSONFactory.CreateInstance("{'configuration':[{'type':'analysisset','analyses':[]},{'type':'analysisset','name':'name2','analyses':[]}]}"));
        }
コード例 #7
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldThrowExceptionWhenJSONHaveCorrectConfigurationTypesButWithAnalysesAsObject()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            analysisSetJSONFactory.CreateInstance("{'configuration':[{'type':'analysisset','analyses':{}},{'type':'analysisset','analyses':{}}]}");
        }
コード例 #8
0
        public void AnalysisSetJSONFactoryCreateInstanceShouldReturnEmptyCreatedListWhenJSONHaveEmptyConfigurationNode()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);
            List <IAnalysisSet>          listOfCreatedSets        = new List <IAnalysisSet>(analysisSetJSONFactory.CreateInstance("{'configuration':[]}"));

            Assert.AreEqual(listOfCreatedSets.Count, 0);
        }
コード例 #9
0
        public void AnalysisSetJSONFactoryConstructorShouldConfigureProperlyRequiredFactories()
        {
            Mock <IAnalysisSetFactory>   analysisSetFactoryMock   = new Mock <IAnalysisSetFactory>();
            Mock <IAnalysisTypesFactory> analysisTypesFactoryMock = new Mock <IAnalysisTypesFactory>();
            AnalysisSetJSONFactory       analysisSetJSONFactory   = new AnalysisSetJSONFactory(analysisSetFactoryMock.Object, analysisTypesFactoryMock.Object);

            Assert.AreEqual(analysisSetJSONFactory.AnalysisSetFactory, analysisSetFactoryMock.Object);
            Assert.AreEqual(analysisSetJSONFactory.AnalysisTypesFactory, analysisTypesFactoryMock.Object);
        }
コード例 #10
0
        public void MeliIntegrationTestShouldWorksWhenConfigurationIsCreatedFromJSON()
        {
            string json = @"
                {
                  'configuration': [
                    {
                      'type': 'analysisset',
                      'name': 'mutant',
                      'analyses': [
                        {
                          'type': 'quantity',
                          'min': 2,
                          'search': [
                            {
                              'type': 'alldirectionssequencequantity',
                              'sequence': 'AAAA'
                            },
                            {
                              'type': 'alldirectionssequencequantity',
                              'sequence': 'TTTT'
                            },
                            {
                              'type': 'alldirectionssequencequantity',
                              'sequence': 'CCCC'
                            },
                            {
                              'type': 'alldirectionssequencequantity',
                              'sequence': 'GGGG'
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
            ";

            /// Creo el Factory Principal, que va a crear la lista de analysis set
            IAnalysisSetFactory analysisSetFactory = new AnalysisSetFactory();

            Mock <IQuantitySearch> quantitySearchMock = new Mock <IQuantitySearch>();
            Mock <IAnalysisResult> resultMock         = new Mock <IAnalysisResult>();
            Mock <IUnityContainer> containerMock      = new Mock <IUnityContainer>();

            containerMock.Setup(m => m.Resolve(typeof(IAnalysisResult), "quantityAnalysisResult", It.IsAny <ParameterOverride>(), It.IsAny <ParameterOverride>(), It.IsAny <ParameterOverride>())).Returns(resultMock.Object);
            containerMock.Setup(m => m.Resolve(typeof(IQuantitySearch), "allDirectionsSequenceQuantitySearch", It.IsAny <ParameterOverride>())).Returns(quantitySearchMock.Object);

            /// Creo el Factory de resultados de analisis de cantidad
            IQuantityAnalysisResultFactory quantityAnalysisResultFactory = new QuantityAnalysisResultFactory(containerMock.Object);
            IQuantityAnalysisFactory       quantityAnalysisFactory       = new QuantityAnalysisFactory(quantityAnalysisResultFactory);

            /// Creo la lista de busquedas por cantidad disponibles
            Dictionary <string, IQuantitySearchJSONFactory> availableSearchFactories = new Dictionary <string, IQuantitySearchJSONFactory>();

            /// Agrego la busqueda por todas las direcciones
            AllDirectionsSequenceQuantitySearchFactory allDirectionsSequenceQuantitySearchFactory = new AllDirectionsSequenceQuantitySearchFactory(containerMock.Object);
            IQuantitySearchJSONFactory allDirectionsQuantityJSONFactory = new QuantitySearchJSONFactory(allDirectionsSequenceQuantitySearchFactory, AllDirectionsSequenceQuantitySearch.ClassType);

            availableSearchFactories.Add(AllDirectionsSequenceQuantitySearch.ClassType, allDirectionsQuantityJSONFactory);

            /// Creo el Factory de busquedas por cantidad, con las busquedas por cantidad disponibles
            IQuantitySearchTypesFactory quantitySearchTypesFactory  = new QuantitySearchTypesFactory(availableSearchFactories);
            QuantityAnalysisJSONFactory quantityAnalysisJSONFactory = new QuantityAnalysisJSONFactory(quantityAnalysisFactory, quantitySearchTypesFactory);

            Dictionary <string, IAnalysisJSONFactory> availableAnalysisFactories = new Dictionary <string, IAnalysisJSONFactory>();

            availableAnalysisFactories.Add(QuantityAnalysis.ClassKey, quantityAnalysisJSONFactory);

            IAnalysisTypesFactory analysisTypesFactory = new AnalysisTypesFactory(availableAnalysisFactories);

            AnalysisSetJSONFactory factory = new AnalysisSetJSONFactory(analysisSetFactory, analysisTypesFactory);

            IEnumerable <IAnalysisSet> analysisSets = factory.CreateInstance(json);

            Assert.IsTrue(analysisSets != null);

            foreach (var analysisSet in analysisSets)
            {
                {
                    IDNAConfiguration dnaConfiguration = this.GetDNAConfiguration();
                    string[]          components       = new string[] { "ATGCGA", "CAGTGC", "TTATGT", "AGAAGG", "CCCCTA", "TCACTG" };
                    IDNA dna = new DNA(dnaConfiguration, components);
                    List <IAnalysisResult> results = new List <IAnalysisResult>(analysisSet.Analyze(dna));
                    Assert.AreEqual(resultMock.Object, results[0]);
                }
            }
        }