Esempio n. 1
0
        public void SuccessfulUpdate()
        {
            // data
            var client = new Core.Data.Model.Client
            {
                Id          = Guid.NewGuid(),
                User_Id     = Guid.NewGuid(),
                Active      = true,
                CreatedDate = DateTime.Now,
                Contacts    = new List <Core.Data.Model.ClientContact>
                {
                    new Core.Data.Model.ClientContact
                    {
                        Id = Guid.NewGuid()
                    }
                }
            };

            // mocks
            var clientPersistor = Mocks.StrictMock <Core.Data.Persistor.Client>();
            var bll             = Mocks.StrictMock <Core.Logic.ClientLogic>(clientPersistor, null);

            // record
            bll.Expect(b => b.Save(client)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            clientPersistor.Expect(u => u.Save(client)).Return(client);
            clientPersistor.Expect(u => u.Commit()).Return(1);

            Mocks.ReplayAll();
            var result = bll.Save(client);

            Assert.Equal(client.Id, result.Id);
        }
Esempio n. 2
0
        public void Successful()
        {
            var persistor = new Core.Data.Persistor.Client();
            var userId    = Guid.Parse("{5CEAD906-4825-4357-A60D-F0363B247CA6}");

            var sql = Utils.User.GetInsertScript(userId, "user 1", "*****@*****.**");

            persistor.DbContext.Database.ExecuteSqlCommand(sql);

            var clientId = Guid.Empty;
            var client   = new Core.Data.Model.Client
            {
                Id          = clientId,
                Active      = true,
                CompanyName = "Client name",
                CreatedDate = DateTime.Now,
                User_Id     = userId,
            };

            persistor.Save(client);
            persistor.Commit();

            const string sqlFormatter = "IF NOT EXISTS (" +
                                        "SELECT COUNT(*) FROM Clients WHERE Id = '{0}' AND CompanyName = '{1}' AND User_Id = '{2}' " +
                                        "HAVING COUNT(*) = 1" +
                                        ") RAISERROR ('Error creating client.',16,1);";

            Assert.NotEqual(clientId, client.Id);

            sql = string.Format(sqlFormatter, client.Id, "Client name", userId);
            persistor.DbContext.Database.ExecuteSqlCommand(sql);
        }
Esempio n. 3
0
        public void UserIdEmpty()
        {
            var client = new Core.Data.Model.Client();

            var ex = Assert.Throws <ArgumentException>(() => new Core.Logic.ClientLogic().Save(client));

            Assert.Equal("User id most be specified to save a client", ex.Message);
        }
Esempio n. 4
0
        public void SuccessfulInsertWithUserIdLookup()
        {
            // data
            var userId    = Guid.NewGuid();
            var invoiceId = Guid.NewGuid();
            var clientId  = Guid.NewGuid();
            var client    = new Core.Data.Model.Client {
                Id = clientId, User_Id = userId
            };
            var invoice = new Core.Data.Model.Invoice
            {
                Id          = Guid.Empty,
                Client_Id   = clientId,
                Active      = true,
                CreatedDate = DateTime.Now,
                Items       = new List <Core.Data.Model.InvoiceItem>
                {
                    new Core.Data.Model.InvoiceItem
                    {
                        Id = Guid.NewGuid()
                    },
                    new Core.Data.Model.InvoiceItem
                    {
                        Id = Guid.NewGuid()
                    }
                }
            };

            // mocks
            var invoicePersistor     = Mocks.StrictMock <Core.Data.Persistor.Invoice>();
            var invoiceItemPersistor = Mocks.StrictMock <Core.Data.Persistor.InvoiceItem>();
            var clientPersistor      = Mocks.StrictMock <Core.Data.Persistor.Client>();
            var bll = Mocks.StrictMock <Core.Logic.InvoiceLogic>(invoicePersistor, invoiceItemPersistor, clientPersistor);

            // record
            bll.Expect(b => b.Save(invoice)).CallOriginalMethod(OriginalCallOptions.NoExpectation);

            clientPersistor.Expect(c => c.Get(invoice.Client_Id)).Return(client);
            bll.Expect(b => b.Save(userId, invoice)).Return(invoice);

            Mocks.ReplayAll();
            var result = bll.Save(invoice);

            Assert.Equal(invoice.Id, result.Id);
        }
Esempio n. 5
0
        public void SuccessfulInsert()
        {
            // data
            var client = new Core.Data.Model.Client
            {
                Id          = Guid.Empty,
                User_Id     = Guid.NewGuid(),
                Active      = true,
                CreatedDate = DateTime.Now,
                Contacts    = new List <Core.Data.Model.ClientContact>
                {
                    new Core.Data.Model.ClientContact
                    {
                        Id = Guid.NewGuid()
                    },
                    new Core.Data.Model.ClientContact
                    {
                        Id = Guid.NewGuid()
                    }
                }
            };

            // mocks
            var clientPersistor        = Mocks.StrictMock <Core.Data.Persistor.Client>();
            var clientContactPersistor = Mocks.StrictMock <Core.Data.Persistor.ClientContact>();
            var bll = Mocks.StrictMock <Core.Logic.ClientLogic>(clientPersistor, clientContactPersistor);

            // record
            bll.Expect(b => b.Save(client)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            clientPersistor.Expect(u => u.Save(client)).Return(client).WhenCalled(c => client.Id = Guid.NewGuid());
            clientContactPersistor.Expect(
                c => c.Save(Arg <Core.Data.Model.ClientContact> .Matches(m => m.Client_Id == client.Id && m.Client_Id != Guid.Empty)))
            .Repeat.Twice();

            clientPersistor.Expect(u => u.Commit()).Return(1);
            clientContactPersistor.Expect(u => u.Commit()).Return(1);

            Mocks.ReplayAll();
            var result = bll.Save(client);

            Assert.Equal(client.Id, result.Id);
        }
Esempio n. 6
0
        public void Successful()
        {
            // data
            var clientId = Guid.NewGuid();
            var client   = new Core.Data.Model.Client {
                Id = clientId
            };

            // mocks
            var clientPersistor = Mocks.StrictMock <Core.Data.Persistor.Client>();
            var bll             = Mocks.StrictMock <Core.Logic.ClientLogic>(clientPersistor, null);

            bll.Expect(b => b.Get(client.Id)).CallOriginalMethod(OriginalCallOptions.NoExpectation);
            clientPersistor.Expect(d => d.Get(client.Id)).Return(client);

            // record
            Mocks.ReplayAll();

            var result = bll.Get(clientId);

            Assert.Equal(clientId, result.Id);
        }