예제 #1
0
        public void Test_AssetTypes_Find()
        {
            IAssetTypesConnector connector = new AssetTypesConnector();

            var newAssetType = new AssetType()
            {
                Description           = "TestAssetType",
                Notes                 = "Some notes",
                Type                  = "1",
                AccountAssetId        = 1150,
                AccountDepreciationId = 7824,
                AccountValueLossId    = 1159,
            };

            var marks = TestUtils.RandomString(3);

            for (var i = 0; i < 5; i++)
            {
                newAssetType.Number = marks + i;
                connector.Create(newAssetType);
                MyAssert.HasNoError(connector);
            }

            var assetTypes = connector.Find();

            Assert.AreEqual(5, assetTypes.Entities.Count(x => x.Number.StartsWith(marks)));

            //restore
            foreach (var entity in assetTypes.Entities.Where(x => x.Number.StartsWith(marks)))
            {
                connector.Delete(entity.Id);
                MyAssert.HasNoError(connector);
            }
        }
예제 #2
0
        public void Test_Find()
        {
            #region Arrange
            var tmpCostCenter = new CostCenterConnector().Get("TMP") ?? new CostCenterConnector().Create(new CostCenter()
            {
                Code = "TMP", Description = "TmpCostCenter"
            });
            var tmpAssetType = new AssetTypesConnector().Create(new AssetType()
            {
                Description = "TmpAssetType", Type = "1", Number = TestUtils.RandomString(3), AccountAssetId = 1150, AccountDepreciationId = 7824, AccountValueLossId = 1159
            });
            #endregion Arrange

            var testKeyMark = TestUtils.RandomString();

            IAssetConnector connector = new AssetConnector();
            var             newAsset  = new Asset()
            {
                Description       = testKeyMark,
                AcquisitionDate   = new DateTime(2011, 1, 1),
                AcquisitionStart  = new DateTime(2011, 2, 1),
                AcquisitionValue  = 500,
                DepreciationFinal = new DateTime(2012, 1, 1),
                Department        = "Some Department",
                Notes             = "Some notes",
                Group             = "Some Group",
                Room       = "Some room",
                Placement  = "Right here",
                CostCenter = tmpCostCenter.Code,
                TypeId     = tmpAssetType.Id.ToString()
            };

            //Add entries
            for (var i = 0; i < 5; i++)
            {
                newAsset.Number = TestUtils.RandomString();
                connector.Create(newAsset);
            }

            //Apply base test filter
            connector.Description = testKeyMark;
            var fullCollection = connector.Find();
            MyAssert.HasNoError(connector);

            Assert.AreEqual(5, fullCollection.TotalResources);
            Assert.AreEqual(5, fullCollection.Entities.Count);
            Assert.AreEqual(1, fullCollection.TotalPages);

            //Apply Limit
            connector.Limit = 2;
            var limitedCollection = connector.Find();
            MyAssert.HasNoError(connector);

            Assert.AreEqual(5, limitedCollection.TotalResources);
            Assert.AreEqual(2, limitedCollection.Entities.Count);
            Assert.AreEqual(3, limitedCollection.TotalPages);

            //Delete entries
            foreach (var entry in fullCollection.Entities)
            {
                connector.Delete(entry.Id);
            }

            #region Delete arranged resources
            new CostCenterConnector().Delete(tmpCostCenter.Code);
            new AssetTypesConnector().Delete(tmpAssetType.Id);
            #endregion Delete arranged resources
        }
예제 #3
0
        public void Test_Asset_CRUD()
        {
            #region Arrange
            var tmpCostCenter = new CostCenterConnector().Get("TMP") ?? new CostCenterConnector().Create(new CostCenter()
            {
                Code = "TMP", Description = "TmpCostCenter"
            });
            var tmpAssetType = new AssetTypesConnector().Create(new AssetType()
            {
                Description = "TmpAssetType", Type = "1", Number = TestUtils.RandomString(3), AccountAssetId = 1150, AccountDepreciationId = 7824, AccountValueLossId = 1159
            });
            #endregion Arrange

            IAssetConnector connector = new AssetConnector();

            #region CREATE
            var newAsset = new Asset()
            {
                Description       = "TestAsset",
                Number            = TestUtils.RandomString(),
                AcquisitionDate   = new DateTime(2011, 1, 1),
                AcquisitionStart  = new DateTime(2011, 2, 1),
                AcquisitionValue  = 500,
                DepreciationFinal = new DateTime(2012, 1, 1),
                Department        = "Some Department",
                Notes             = "Some notes",
                Group             = "Some Group",
                Room       = "Some room",
                Placement  = "Right here",
                CostCenter = tmpCostCenter.Code,
                TypeId     = tmpAssetType.Id.ToString()
            };

            var createdAsset = connector.Create(newAsset);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("TestAsset", createdAsset.Description); //returns entity named "Assets" instead of "asset"

            #endregion CREATE

            #region UPDATE

            createdAsset.Description = "UpdatedTestAsset";

            var updatedAsset = connector.Update(createdAsset);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestAsset", updatedAsset.Description);

            #endregion UPDATE

            #region READ / GET

            var retrievedAsset = connector.Get(createdAsset.Id);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestAsset", retrievedAsset.Description);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdAsset.Id);
            MyAssert.HasNoError(connector);

            retrievedAsset = connector.Get(createdAsset.Id);
            Assert.AreEqual(null, retrievedAsset, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new CostCenterConnector().Delete(tmpCostCenter.Code);
            new AssetTypesConnector().Delete(tmpAssetType.Id);
            #endregion Delete arranged resources
        }
예제 #4
0
        public void Test_AssetTypes_CRUD()
        {
            #region Arrange

            //Add code to create required resources

            #endregion Arrange

            IAssetTypesConnector connector = new AssetTypesConnector();
            var entry = connector.Find().Entities.FirstOrDefault(at => at.Number == "TST");
            if (entry != null)
            {
                connector.Delete(entry.Id);
            }

            #region CREATE

            var newAssetTypes = new AssetType()
            {
                Description           = "TestAssetType",
                Notes                 = "Some notes",
                Number                = "TST",
                Type                  = "1",
                AccountAssetId        = 1150,
                AccountDepreciationId = 7824,
                AccountValueLossId    = 1159,
            };

            var createdAssetTypes = connector.Create(newAssetTypes);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("TestAssetType",
                            createdAssetTypes.Description); //Fails due to response entity is named "Type", not "AssetType"

            #endregion CREATE

            #region UPDATE

            createdAssetTypes.Description = "UpdatedTestAssetType";

            var updatedAssetTypes = connector.Update(createdAssetTypes);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestAssetType", updatedAssetTypes.Description);

            #endregion UPDATE

            #region READ / GET

            var retrievedAssetTypes = connector.Get(createdAssetTypes.Id);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestAssetType", retrievedAssetTypes.Description);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdAssetTypes.Id);
            MyAssert.HasNoError(connector);

            retrievedAssetTypes = connector.Get(createdAssetTypes.Id);
            Assert.AreEqual(null, retrievedAssetTypes, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources

            //Add code to delete temporary resources

            #endregion Delete arranged resources
        }
        public void Test_AssetFileConnection_CRUD()
        {
            #region Arrange
            var tmpAssetType = new AssetTypesConnector().Create(new AssetType()
            {
                Description = "TmpAssetType", Type = "1", Number = TestUtils.RandomString(3), AccountAssetId = 1150, AccountDepreciationId = 7824, AccountValueLossId = 1159
            });
            var tmpAsset = new AssetConnector().Create(new Asset()
            {
                Description       = "TestAsset",
                Number            = TestUtils.RandomString(),
                AcquisitionDate   = new DateTime(2011, 1, 1),
                AcquisitionStart  = new DateTime(2011, 2, 1),
                AcquisitionValue  = 500,
                DepreciationFinal = new DateTime(2012, 1, 1),
                Department        = "Some Department",
                Notes             = "Some notes",
                Group             = "Some Group",
                Room      = "Some room",
                Placement = "Right here",
                TypeId    = tmpAssetType.Id.ToString()
            });
            var tmpFile = new ArchiveConnector().UploadFile("tmpImage.png", Resource.fortnox_image);
            #endregion Arrange

            IAssetFileConnectionConnector connector = new AssetFileConnectionConnector();

            #region CREATE
            var newAssetFileConnection = new AssetFileConnection()
            {
                FileId  = tmpFile.Id,
                AssetId = tmpAsset.Id
            };

            var createdAssetFileConnection = connector.Create(newAssetFileConnection);
            Assert.AreEqual(tmpAsset.Id, createdAssetFileConnection.AssetId);

            #endregion CREATE

            #region UPDATE
            //Update not supported
            #endregion UPDATE

            #region READ / GET

            var retrievedAssetFileConnection = connector.Get(createdAssetFileConnection.FileId);
            Assert.AreEqual(tmpAsset.Id, retrievedAssetFileConnection.AssetId);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdAssetFileConnection.FileId);

            /*Assert.ThrowsException<FortnoxApiException>(
             *  () => connector.Get(createdAssetFileConnection.FileId),
             *  "Entity still exists after Delete!");*/

            //For some reason, connection exists after delete, but with asset id set to null
            retrievedAssetFileConnection = connector.Get(createdAssetFileConnection.FileId);
            Assert.AreEqual(null, retrievedAssetFileConnection.AssetId, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new AssetConnector().Delete(tmpAsset.Id);
            new AssetTypesConnector().Delete(tmpAssetType.Id);
            new ArchiveConnector().DeleteFile(tmpFile.Id);
            #endregion Delete arranged resources
        }