public void ShouldBeAbleToBroadcastMessagesAndReceiveResponses()
        {
            var sampleClusterConfiguration = BuildSampleClusterConfiguration();

            var testServer1 = SetupTestServerForNode(sampleClusterConfiguration.Nodes[0]);
            testServer1.Start();

            var testServer2 = SetupTestServerForNode(sampleClusterConfiguration.Nodes[1]);
            testServer2.Start();

            var sut = new NetMqRpcChannel(sampleClusterConfiguration, TimeSpan.FromMilliseconds(200));

            var sampleRequest = new SampleRequest("test");

            var autoResetEvent = new AutoResetEvent(false);

            int expectedNumberOfResponses = sampleClusterConfiguration.Nodes.Length;
            var responses = new List<SampleResponse>();

            sut.Broadcast<SampleRequest, SampleResponse>(sampleRequest, response =>
            {
                responses.Add(response);

                if (responses.Count >= expectedNumberOfResponses)
                {
                    autoResetEvent.Set();
                }
            });

            autoResetEvent.WaitOne(TimeSpan.FromSeconds(1));

            Assert.AreEqual(expectedNumberOfResponses, responses.Count);
            Assert.IsNotNull(responses.SingleOrDefault(x => x.ResponseString == sampleClusterConfiguration.Nodes[0].Id.ToString()));
            Assert.IsNotNull(responses.SingleOrDefault(x => x.ResponseString == sampleClusterConfiguration.Nodes[1].Id.ToString()));
        }
Пример #2
0
        public void when_processing_batches()
        {
            var orders = Enumerable.Range(1, 20).Select(x => new Order {Id = x}).ToList();

            var batches = new List<List<Order>>();

            Action<List<Order>> action = batches.Add;

            var orderBatcher = new OrderBatcher();
            orderBatcher.ProcessBatches(orders, action);

            Assert.That(batches.Count, Is.EqualTo(4), "It should have processed the orders in 4 batches");

            Assert.That(batches.SingleOrDefault(x => x.First().Id == 1 && x.Last().Id == 5), Is.Not.Null, "It should have processed the 1st batch");
            Assert.That(batches.SingleOrDefault(x => x.First().Id == 6 && x.Last().Id == 10), Is.Not.Null, "It should have processed the 2nd batch");
            Assert.That(batches.SingleOrDefault(x => x.First().Id == 11 && x.Last().Id == 15), Is.Not.Null, "It should have processed the 3rd batch");
            Assert.That(batches.SingleOrDefault(x => x.First().Id == 16 && x.Last().Id == 20), Is.Not.Null, "It should have processed the 4th batch");
        }
Пример #3
0
 public static void AreEqual(XmlNodeList tlgNodes, string currentPath, List<OperationData> operationData)
 {
     Assert.AreEqual(tlgNodes.Count, operationData.Count);
     for (int i = 0; i < tlgNodes.Count; i++)
     {
         var matchingOperationData = operationData.SingleOrDefault(x => x.Id.FindIsoId() == tlgNodes[i].Attributes["A"].Value);
         AreEqual(tlgNodes[i], currentPath, matchingOperationData);
     }
 }
 private void AssertEnvironmentConfigurationList(List<DeployEnvironmentConfiguration> expectedList, List<DeployEnvironmentConfiguration> actualList)
 {
     expectedList = (expectedList ?? new List<DeployEnvironmentConfiguration>());
     actualList = (actualList ?? new List<DeployEnvironmentConfiguration>());
     Assert.AreEqual(expectedList.Count(), actualList.Count);
     foreach (var expectedItem in expectedList)
     {
         var actualItem = actualList.SingleOrDefault(i => i.ParentId == expectedItem.ParentId);
         AssertEnvironmentConfiguration(expectedItem, actualItem);
     }
 }
Пример #5
0
 static void CheckIndex(TestDb db, List<IndexInfo> indexes, string iname, bool unique, params string [] columns)
 {
     if (columns == null)
         throw new Exception ("Don't!");
     var idx = indexes.SingleOrDefault (i => i.name == iname);
     Assert.IsNotNull (idx, String.Format ("Index {0} not found", iname));
     Assert.AreEqual (idx.unique, unique, String.Format ("Index {0} unique expected {1} but got {2}", iname, unique, idx.unique));
     var idx_columns = db.Query<IndexColumns> (String.Format ("PRAGMA INDEX_INFO (\"{0}\")", iname));
     Assert.AreEqual (columns.Length, idx_columns.Count, String.Format ("# of columns: expected {0}, got {1}", columns.Length, idx_columns.Count));
     foreach (var col in columns) {
         Assert.IsNotNull (idx_columns.SingleOrDefault (c => c.name == col), String.Format ("Column {0} not in index {1}", col, idx.name));
     }
 }
Пример #6
0
        public static void AreEqual(XmlNodeList tskNodes, string currentPath, List<LoggedData> loggedData, Catalog catalog)
        {
            int tsksWithTlgs = 0;
            foreach (XmlNode node in tskNodes)
            {
                if (node.SelectNodes("TLG").Count > 0)
                {
                    tsksWithTlgs++;

                    var matchingLoggedData = loggedData.SingleOrDefault(x => x.Id.FindIsoId() == node.Attributes["A"].Value);
                    AreEqual(node, currentPath, matchingLoggedData, catalog);
                }
            }

            Assert.AreEqual(tsksWithTlgs, loggedData.Count);
        }
        public void SetUp()
        {
            _collectionWrapper = Substitute.For<ICollectionWrapper<StreamReadModel, Int64>>();
            rmStream = new List<StreamReadModel>();
            rmDocuments = new List<DocumentDescriptorReadModel>();

            _collectionWrapper.When(r => r.Insert(
                Arg.Any<DomainEvent>(),
                Arg.Any<StreamReadModel>()))
                .Do(cinfo => rmStream.Add((StreamReadModel)cinfo.Args()[1]));
            _collectionWrapper.All.Returns(rmStream.AsQueryable());

            _readerDocumentReadModel = Substitute.For<IReader<DocumentDescriptorReadModel, DocumentDescriptorId>>();
            _readerDocumentReadModel.AllUnsorted.Returns(rmDocuments.AsQueryable());
            _readerDocumentReadModel.AllSortedById.Returns(rmDocuments.AsQueryable().OrderBy(r => r.Id));
            _readerDocumentReadModel.FindOneById(Arg.Any<DocumentDescriptorId>())
                .Returns(cinfo => rmDocuments.SingleOrDefault(d => d.Id == (DocumentDescriptorId)cinfo.Args()[0]));

            _handleWriter = Substitute.For<IDocumentWriter>();
            _blobStore = Substitute.For<IBlobStore>();
        }
Пример #8
0
        internal static void AssertFileContentIsCorrect(string file, string repositoryName, List<RequestEntityImp> allRequests = null)
        {
            var document = new XmlDocument();
            document.Load(file);

            var documentElement = document.DocumentElement;
            Assert.That(documentElement, Is.Not.Null);

            // ReSharper disable PossibleNullReferenceException
            var documentName = documentElement.GetAttribute("Name");
            // ReSharper restore PossibleNullReferenceException

            Assert.That(documentName, Is.EqualTo(repositoryName));

            var requestsElement = documentElement.SelectSingleNode("Requests");
            Assert.That(requestsElement, Is.Not.Null);

            if (allRequests != null)
            {
            // ReSharper disable PossibleNullReferenceException
                Assert.That(requestsElement.ChildNodes.Count, Is.EqualTo(allRequests.Count));

                foreach (XmlElement requestElement in requestsElement.ChildNodes)
                {
                    var id = requestElement.GetAttribute("Id");
                    Assert.That(id, Is.Not.Null.Or.Empty);

                    Assert.That(allRequests.SingleOrDefault(r => r.PersistentId == id), Is.Not.Null);
                }
            // ReSharper restore PossibleNullReferenceException
            }
        }
        public void Run_SupplySettingToDeleteFromTargetFolder_AllFilesAreDeleted()
        {
            // arrange
            _settings = new RandomizerWorkerSettings
            {
                DeleteFromTargetFolder = true,
                PathTo = "path to"
            };

            List<AppFile> files = new List<AppFile>
            {
                new AppFile { },
                new AppFile { },
                new AppFile { }
            };

            _fileServiceMock.Setup(x => x.GetFiles(_settings.PathTo)).Returns(files);

            _fileServiceMock
                .Setup(x => x.DeleteFile(It.IsAny<AppFile>()))
                .Callback((AppFile file) =>
                {
                    Assert.That(file, Is.EqualTo(files.SingleOrDefault(x => x == file)));
                });

            // act, assert
            _worker.Run(_settings, (x) => { }, (y) => { }, () => { });

            _backgroundWorkerMock.Raise(x => { x.OnDoWork += null; }, null, new System.ComponentModel.DoWorkEventArgs(null));
        }
        public void atualizar_estrutura_hospitalar_departamentoExistentes()
        {
            var tiposConta = new TiposConta();
            var tiposDeconta = new TiposConta();
            var tipoContaOutras = tiposDeconta.Obter<TipoConta>(1);

            string _conectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;";
            _conectionstring += String.Format("Data Source={0};", "D:\\CargaOrcamento2014\\DepartamentoCentroDeCustoContaHospitalarNew.xls");
            _conectionstring += "Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";

            var cn = new OleDbConnection(_conectionstring);
            var cmd = new OleDbCommand("Select * from [c$]", cn);
            cn.Open();
            var reader = cmd.ExecuteReader();

            var documento = new List<RegistroExcel>();

            var listaContas = new List<Conta>();
            var listaCentrosDeCusto = new List<CentroDeCusto>();

            var repositorioDeHospitais = new Hospitais();
            var repositorioDeCusto = new CentrosDeCusto();
            var repositorioContas = new Contas();

            int i = 0;

            while (reader.Read())
            {
                if (i == 0)
                {
                    i++;
                    continue;
                }
                if (reader[0] == null || reader[0] == DBNull.Value || string.IsNullOrEmpty(reader[0].ToString()))
                    break;

                var registroExcel = new RegistroExcel()
                {
                    NomeHospital = (string)reader[5],
                    CodigoCentroDeCusto = Convert.ToString(reader[0]),
                    DescricaoCentroDeCusto = (string)reader[1]
                };

                if (reader[5] != DBNull.Value)
                {
                    registroExcel.DescricaoConta = (string)reader[3];
                    registroExcel.CodigoConta = Convert.ToString(reader[2]);
                    registroExcel.GrupoResumoNome = (string)reader[4];
                }

                documento.Add(registroExcel);
            }

            cn.Close();
            cn.Dispose();
            cmd.Dispose();

            var gruposDeConta = documento.Select(x => x.GrupoResumoNome).Distinct();

            var codigosDeConta = documento.Select(x => x.CodigoConta).Distinct();

            foreach (var codigoDeConta in codigosDeConta)
            {
                string descricaoDaConta = documento.Where(x => x.CodigoConta == codigoDeConta).Select(y => y.DescricaoConta).Distinct().First();

                var conta = repositorioContas.ObterContaPor(codigoDeConta);

                if (listaContas.All(c => c.CodigoDaConta != codigoDeConta))
                {
                    if (conta == null)
                    {
                        throw new Exception();

                        conta = new Conta(descricaoDaConta, tipoContaOutras)
                        {
                            CodigoDaConta = codigoDeConta
                        };
                        repositorioContas.Salvar(conta);
                    }

                    listaContas.Add(conta);
                }
                else
                    conta = listaContas.FirstOrDefault(c => c.CodigoDaConta == codigoDeConta);

            }
            var grupos = new GruposDeConta();
            var gruposDeContaLista = new List<GrupoDeConta>();
            foreach (var grupo in gruposDeConta)
            {
                var grupoDeConta = grupos.ObterPor(grupo);

                if (grupoDeConta == null)
                    throw new Exception();

                var contasDoGrupo = documento.Where(x => x.GrupoResumoNome == grupo).Select(y => y.CodigoConta).Distinct();

                foreach (var codigoConta in contasDoGrupo)
                {
                    var conta = listaContas.FirstOrDefault(c => c.CodigoDaConta == codigoConta);

                    if (grupoDeConta.Contas == null)
                        grupoDeConta.Contas = new List<Conta>();

                    if (grupoDeConta.Contas.All(c => c.CodigoDaConta != codigoConta))
                        grupoDeConta.Adicionar(conta);
                }

                gruposDeContaLista.Add(grupoDeConta);
                grupos.Salvar(grupoDeConta);
            }

            var codigosDecentrosDeCusto = documento.Select(x => x.CodigoCentroDeCusto).Distinct();

            foreach (var codigoDeCentro in codigosDecentrosDeCusto)
            {
                var descricaoDeCentroDeCusto = documento.Where(x => x.CodigoCentroDeCusto == codigoDeCentro).Select(y => y.DescricaoCentroDeCusto).Distinct().First();

                var centroDeCusto = repositorioDeCusto.ObterPor(codigoDeCentro);
                if (centroDeCusto == null)
                {
                        throw new Exception();

                    centroDeCusto = new CentroDeCusto(descricaoDeCentroDeCusto)
                    {
                        CodigoDoCentroDeCusto = codigoDeCentro
                    };
                }

                var contas = documento.Where(x => x.CodigoCentroDeCusto == codigoDeCentro).Select(y => y.CodigoConta).Distinct();

                if (centroDeCusto.Contas == null)
                    centroDeCusto.Contas = new List<Conta>();

                foreach (var conta in contas)
                {
                    if (centroDeCusto.Contas.All(c => c.CodigoDaConta != conta))
                        centroDeCusto.AdicionarConta(listaContas.SingleOrDefault(x => x.CodigoDaConta == conta));
                }

                repositorioDeCusto.Salvar(centroDeCusto);
                listaCentrosDeCusto.Add(centroDeCusto);
            }

            var hospitais = documento.Select(x => x.NomeHospital).Distinct();

            foreach (var nomeHospital in hospitais)
            {
                var hospital = repositorioDeHospitais.ObterPor(nomeHospital);
                if(hospital == null)
                    throw new Exception();

                var centrosDeCusto = documento.Where(x => x.NomeHospital == hospital.Nome).Select(y => y.CodigoCentroDeCusto).Distinct();

                if (hospital.CentrosDeCusto == null)
                    hospital.CentrosDeCusto = new List<CentroDeCusto>();

                foreach (var codigoCentroCusto in centrosDeCusto)
                {
                    if (hospital.CentrosDeCusto.All(c => c.CodigoDoCentroDeCusto != codigoCentroCusto))
                        hospital.AdicionarCentroDeCusto(listaCentrosDeCusto.SingleOrDefault(x => x.CodigoDoCentroDeCusto == codigoCentroCusto));
                }

                repositorioDeHospitais.Salvar(hospital);
            }
        }
Пример #11
0
        private void VerifyInvoiceItemsAreEqual(string layout, List<InvoiceTransactionLineItem> list1, List<InvoiceTransactionLineItem> list2)
        {
            if (list1 == null || list2 == null)
            {
                Assert.IsTrue(list1 == null && list2 == null, "One list is NULL and the other is not. Expected both to be NULL");
                return;
            }

            Assert.AreEqual(list1.Count, list2.Count, "Number of items are different");

            if (layout == "S")
            {
                foreach (var item in list1)
                {
                    var itemInList2 = list2.SingleOrDefault(i => i.Description == item.Description &&
                        i.AccountId == item.AccountId &&
                        i.TaxCode == item.TaxCode
                        );

                    Assert.IsNotNull(itemInList2, "Service item differs in first list");
                }

                foreach (var item in list2)
                {
                    var itemInList1 = list1.SingleOrDefault(i => i.Description == item.Description &&
                        i.AccountId == item.AccountId &&
                        i.TaxCode == item.TaxCode
                        );

                    Assert.IsNotNull(itemInList1, "Service item differs in second list");
                }
            }
            else
            {
                foreach (var item in list1)
                {
                    var itemInList2 = list2.SingleOrDefault(i => i.Description == item.Description &&
                        i.AccountId == item.AccountId &&
                        i.TaxCode == item.TaxCode &&
                        i.Quantity == item.Quantity &&
                        i.UnitPrice == item.UnitPrice &&
                        i.PercentageDiscount == item.PercentageDiscount &&
                        i.InventoryId == item.InventoryId
                        );

                    Assert.IsNotNull(itemInList2, "Line item differs in first list");
                }

                foreach (var item in list2)
                {
                    var itemInList1 = list1.SingleOrDefault(i => i.Description == item.Description &&
                            i.AccountId == item.AccountId &&
                        i.TaxCode == item.TaxCode &&
                        i.Quantity == item.Quantity &&
                        i.UnitPrice == item.UnitPrice &&
                        i.PercentageDiscount == item.PercentageDiscount &&
                        i.InventoryId == item.InventoryId
                        );

                    Assert.IsNotNull(itemInList1, "Line item differs in second list");
                }
            }
        }
Пример #12
0
        private void VerifyInvoiceAttachmentsAreEqual(List<FileAttachmentInfo> list1, List<FileAttachmentInfo> list2)
        {
            if (list1 == null || list2 == null || list1.Count == 0 || list2.Count == 0)
            {
                //this is because an insert may have sent attachments as null but a GET will return them as empy list.
                Assert.IsTrue(list1 == null || list1.Count == 0, "Expected no items but list1 had some");
                Assert.IsTrue(list2 == null || list2.Count == 0, "Expected no items but list2 had some");
                return;
            }

            foreach (var detail in list1)
            {
                var detailInList2 = list2.SingleOrDefault(d => d.Id == detail.Id && d.Name == detail.Name && d.Description == detail.Description);
                Assert.IsNotNull(detailInList2, "Attachments do not match");
            }

            foreach (var detail in list2)
            {
                var detailInList1 = list1.SingleOrDefault(d => d.Id == detail.Id && d.Name == detail.Name && d.Description == detail.Description);
                Assert.IsNotNull(detailInList1, "Attachments do not match");
            }
        }
Пример #13
0
        public void ListExtensions_SingleOrDefault_ThrowsExceptionIfListHasMultipleItems()
        {
            var list = new List<Int32>() { 1, 2 };

            Assert.That(() => list.SingleOrDefault(),
                Throws.TypeOf<InvalidOperationException>());
        }
Пример #14
0
        public void ListExtensions_SingleOrDefault_ReturnsSingleItemInList()
        {
            var list = new List<Int32>() { 4 };

            var result = list.SingleOrDefault();

            TheResultingValue(result).ShouldBe(4);
        }
Пример #15
0
        public void ListExtensions_SingleOrDefault_ReturnsDefaultValueIfListIsEmpty()
        {
            var list = new List<Int32>();

            var result = list.SingleOrDefault();

            TheResultingValue(result).ShouldBe(default(Int32));
        }