AttendanceTransaction GetNewOrExistingAttendanceTransaction()
        {
            var result = _connector.Find();

            CheckForError(_connector);

            if (result.AttendanceTransactionSubset.Any())
            {
                return(result.AttendanceTransactionSubset.First());
            }

            var employee = CreateEmployee();
            var date     = NewAttendanceTransactionDate.ToString("yyyy-MM-dd");
            var attendanceTransactionToCreate = new AttendanceTransaction
            {
                EmployeeId = employee.EmployeeId,
                Date       = date,
                CauseCode  = AttendanceCauseCode.ARB,
            };
            var attendanceTransaction = _connector.Create(attendanceTransactionToCreate);

            CheckForError(_connector);

            return(attendanceTransaction);
        }
        public void UpdateShouldUpdateAnAttendanceTransaction()
        {
            //Arrange
            var employee = CreateEmployee();
            var date     = NewAttendanceTransactionDate.AddDays(1).ToString("yyyy-MM-dd");
            var create   = new AttendanceTransaction
            {
                EmployeeId = employee.EmployeeId,
                Date       = date,
                CauseCode  = AttendanceCauseCode.ARB,
            };

            var createResult = _connector.Create(create);

            CheckForError(_connector);

            //Act
            var costCenter = GetExistingCostCenter();
            var update     = new AttendanceTransaction
            {
                EmployeeId = employee.EmployeeId,
                Date       = date,
                CauseCode  = AttendanceCauseCode.ARB,
                CostCenter = costCenter.Code,
            };

            var updateResult = _connector.Update(update);

            CheckForError(_connector);

            //Assert
            Assert.AreEqual(update.CostCenter, updateResult.CostCenter);
        }
        public void CreateShouldCreateAnAttendanceTransaction()
        {
            var employee = CreateEmployee();
            var date     = NewAttendanceTransactionDate.ToString("yyyy-MM-dd");
            var attendanceTransaction = new AttendanceTransaction
            {
                EmployeeId = employee.EmployeeId,
                Date       = date,
                CauseCode  = AttendanceCauseCode.ARB,
            };

            var result = _connector.Create(attendanceTransaction);

            CheckForError(_connector);

            Assert.IsNotNull(result.EmployeeId);
            Assert.IsNotNull(result.Date);
            Assert.IsNotNull(result.CauseCode);
            Assert.AreEqual(AttendanceCauseCode.ARB, result.CauseCode);
            Assert.AreEqual(date, result.Date);
        }
        public static async Task <AttendanceTransaction> UpdateAttendanceTransactionAsync(FortnoxApiRequest request, AttendanceTransaction attendanceTransaction)
        {
            var apiRequest =
                new FortnoxApiClientRequest <SingleResource <AttendanceTransaction> >(HttpMethod.Put, request.AccessToken, request.ClientSecret,
                                                                                      $"{ApiEndpoints.AttendanceTransactions}/{attendanceTransaction.EmployeeId}/{attendanceTransaction.Date}/{attendanceTransaction.CauseCode}")
            {
                Data = new SingleResource <AttendanceTransaction> {
                    Data = attendanceTransaction
                }
            };

            return((await FortnoxAPIClient.CallAsync(apiRequest)).Data);
        }
        public void Test_Find()
        {
            #region Arrange
            var tmpEmployee = new EmployeeConnector().Get("TEST_EMP") ?? new EmployeeConnector().Create(new Employee()
            {
                EmployeeId = "TEST_EMP"
            });
            var tmpProject = new ProjectConnector().Create(new Project()
            {
                Description = "TmpProject"
            });
            var tmpCostCenter = new CostCenterConnector().Get("TMP") ?? new CostCenterConnector().Create(new CostCenter()
            {
                Code = "TMP", Description = "TmpCostCenter"
            });

            for (var i = 0; i < 5; i++)
            {
                new AttendanceTransactionsConnector().Delete(tmpEmployee.EmployeeId, new DateTime(2018, 01, 01).AddDays(i), AttendanceCauseCode.TID);
            }
            #endregion Arrange

            IAttendanceTransactionsConnector connector = new AttendanceTransactionsConnector();

            var newAttendenceTransaction = new AttendanceTransaction()
            {
                EmployeeId = tmpEmployee.EmployeeId,
                CauseCode  = AttendanceCauseCode.TID,
                Date       = new DateTime(2018, 01, 01),
                Hours      = 1,
                CostCenter = tmpCostCenter.Code,
                Project    = tmpProject.ProjectNumber
            };

            //Add entries
            for (var i = 0; i < 5; i++)
            {
                newAttendenceTransaction.Date = new DateTime(2018, 01, 01).AddDays(i);
                connector.Create(newAttendenceTransaction);
                MyAssert.HasNoError(connector);
            }

            connector.Search.EmployeeId = tmpEmployee.EmployeeId;
            var fullCollection = connector.Find();
            MyAssert.HasNoError(connector);

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

            Assert.AreEqual(tmpEmployee.EmployeeId, fullCollection.Entities.First().EmployeeId);

            //Apply Limit
            connector.Search.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.EmployeeId, entry.Date, entry.CauseCode);
            }

            #region Delete arranged resources
            new CostCenterConnector().Delete(tmpCostCenter.Code);
            new ProjectConnector().Delete(tmpProject.ProjectNumber);
            #endregion Delete arranged resources
        }
        public void Test_AttendanceTransactions_CRUD()
        {
            #region Arrange
            var tmpEmployee = new EmployeeConnector().Get("TEST_EMP") ?? new EmployeeConnector().Create(new Employee()
            {
                EmployeeId = "TEST_EMP"
            });
            var tmpProject = new ProjectConnector().Create(new Project()
            {
                Description = "TmpProject"
            });
            var tmpCostCenter = new CostCenterConnector().Get("TMP") ?? new CostCenterConnector().Create(new CostCenter()
            {
                Code = "TMP", Description = "TmpCostCenter"
            });
            #endregion Arrange

            IAttendanceTransactionsConnector connector = new AttendanceTransactionsConnector();

            #region CREATE
            var newAttendanceTransaction = new AttendanceTransaction()
            {
                EmployeeId = tmpEmployee.EmployeeId,
                CauseCode  = AttendanceCauseCode.TID,
                Date       = new DateTime(2018, 01, 01),
                Hours      = 5.5m,
                CostCenter = tmpCostCenter.Code,
                Project    = tmpProject.ProjectNumber
            };

            var createdAttendanceTransaction = connector.Create(newAttendanceTransaction);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(5.5m, createdAttendanceTransaction.Hours);

            #endregion CREATE

            #region UPDATE

            createdAttendanceTransaction.Hours = 8;

            var updatedAttendanceTransaction = connector.Update(createdAttendanceTransaction);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(8, updatedAttendanceTransaction.Hours);

            #endregion UPDATE

            #region READ / GET

            var retrievedAttendanceTransaction = connector.Get(createdAttendanceTransaction.EmployeeId, createdAttendanceTransaction.Date, createdAttendanceTransaction.CauseCode);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(8, retrievedAttendanceTransaction.Hours);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdAttendanceTransaction.EmployeeId, createdAttendanceTransaction.Date, createdAttendanceTransaction.CauseCode);
            MyAssert.HasNoError(connector);

            retrievedAttendanceTransaction = connector.Get(createdAttendanceTransaction.EmployeeId, createdAttendanceTransaction.Date, createdAttendanceTransaction.CauseCode);
            Assert.AreEqual(null, retrievedAttendanceTransaction, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new CostCenterConnector().Delete(tmpCostCenter.Code);
            new ProjectConnector().Delete(tmpProject.ProjectNumber);
            #endregion Delete arranged resources
        }
Exemplo n.º 7
0
 public async Task <AttendanceTransaction> CreateAsync(AttendanceTransaction attendanceTransaction)
 {
     return(await BaseCreate(attendanceTransaction).ConfigureAwait(false));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new attendanceTransaction
 /// </summary>
 /// <param name="attendanceTransaction">The attendanceTransaction to create</param>
 /// <returns>The created attendanceTransaction</returns>
 public AttendanceTransaction Create(AttendanceTransaction attendanceTransaction)
 {
     return(CreateAsync(attendanceTransaction).Result);
 }
Exemplo n.º 9
0
 public async Task <AttendanceTransaction> UpdateAsync(AttendanceTransaction attendanceTransaction)
 {
     return(await BaseUpdate(attendanceTransaction, attendanceTransaction.EmployeeId, attendanceTransaction.Date?.ToString(APIConstants.DateFormat), attendanceTransaction.CauseCode?.GetStringValue()).ConfigureAwait(false));
 }
Exemplo n.º 10
0
 public async Task <AttendanceTransaction> CreateAsync(AttendanceTransaction attendanceTransaction)
 {
     return(await BaseCreate(attendanceTransaction));
 }
    public async Task Test_Find()
    {
        #region Arrange
        var tmpEmployee = await FortnoxClient.EmployeeConnector.CreateAsync(new Employee()
        {
            EmployeeId = TestUtils.RandomString()
        });

        var tmpProject = await FortnoxClient.ProjectConnector.CreateAsync(new Project()
        {
            Description = "TmpProject"
        });

        var tmpCostCenter = await FortnoxClient.CostCenterConnector.CreateAsync(new CostCenter()
        {
            Code = "TMP", Description = "TmpCostCenter"
        });

        #endregion Arrange

        var connector = FortnoxClient.AttendanceTransactionsConnector;

        var newAttendenceTransaction = new AttendanceTransaction()
        {
            EmployeeId = tmpEmployee.EmployeeId,
            CauseCode  = AttendanceCauseCode.TID,
            Date       = new DateTime(2018, 01, 01),
            Hours      = 1,
            CostCenter = tmpCostCenter.Code,
            Project    = tmpProject.ProjectNumber
        };

        //Add entries
        for (var i = 0; i < 5; i++)
        {
            newAttendenceTransaction.Date = new DateTime(2018, 01, 01).AddDays(i);
            await connector.CreateAsync(newAttendenceTransaction);
        }

        var searchSettings = new AttendanceTransactionsSearch();
        searchSettings.EmployeeId = tmpEmployee.EmployeeId;
        var fullCollection = await connector.FindAsync(searchSettings);

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

        Assert.AreEqual(tmpEmployee.EmployeeId, fullCollection.Entities.First().EmployeeId);
        Assert.IsNotNull(fullCollection.Entities.First().Url);

        //Apply Limit
        searchSettings.Limit = 2;
        var limitedCollection = await connector.FindAsync(searchSettings);

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

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

        #region Delete arranged resources
        await FortnoxClient.CostCenterConnector.DeleteAsync(tmpCostCenter.Code);

        await FortnoxClient.ProjectConnector.DeleteAsync(tmpProject.ProjectNumber);

        #endregion Delete arranged resources
    }
    public async Task Test_AttendanceTransactions_CRUD()
    {
        #region Arrange
        var tmpEmployee = await FortnoxClient.EmployeeConnector.CreateAsync(new Employee()
        {
            EmployeeId = TestUtils.RandomString()
        });

        var tmpProject = await FortnoxClient.ProjectConnector.CreateAsync(new Project()
        {
            Description = "TmpProject"
        });

        var tmpCostCenter = await FortnoxClient.CostCenterConnector.CreateAsync(new CostCenter()
        {
            Code = "TMP", Description = "TmpCostCenter"
        });

        #endregion Arrange

        var connector = FortnoxClient.AttendanceTransactionsConnector;

        #region CREATE
        var newAttendanceTransaction = new AttendanceTransaction()
        {
            EmployeeId = tmpEmployee.EmployeeId,
            CauseCode  = AttendanceCauseCode.TID,
            Date       = new DateTime(2018, 01, 01),
            Hours      = 5.5m,
            CostCenter = tmpCostCenter.Code,
            Project    = tmpProject.ProjectNumber
        };

        var createdAttendanceTransaction = await connector.CreateAsync(newAttendanceTransaction);

        Assert.AreEqual(5.5m, createdAttendanceTransaction.Hours);

        #endregion CREATE

        #region UPDATE

        createdAttendanceTransaction.Hours = 8;

        var updatedAttendanceTransaction = await connector.UpdateAsync(createdAttendanceTransaction);

        Assert.AreEqual(8, updatedAttendanceTransaction.Hours);

        #endregion UPDATE

        #region READ / GET

        var retrievedAttendanceTransaction = await connector.GetAsync(createdAttendanceTransaction.Id);

        Assert.AreEqual(8, retrievedAttendanceTransaction.Hours);
        Assert.IsNotNull(retrievedAttendanceTransaction.Url);

        #endregion READ / GET

        #region DELETE

        await connector.DeleteAsync(createdAttendanceTransaction.Id);

        await Assert.ThrowsExceptionAsync <FortnoxApiException>(
            async() => await connector.GetAsync(createdAttendanceTransaction.Id),
            "Entity still exists after Delete!");

        #endregion DELETE

        #region Delete arranged resources
        await FortnoxClient.CostCenterConnector.DeleteAsync(tmpCostCenter.Code);

        await FortnoxClient.ProjectConnector.DeleteAsync(tmpProject.ProjectNumber);

        #endregion Delete arranged resources
    }