Skip to content

Conversation

@mwereda
Copy link

@mwereda mwereda commented Mar 17, 2017

No description provided.

/// Gets a new System.Diagnostics.Process component and associates it with the currently active process.
/// </summary>
/// <returns>A new System.Diagnostics.Process component associated with the process resource that is running the calling application.</returns>
Process GetCurrentProcess();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return the IProcess interface to allow proper mocking.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation of this method calls static Process.GetCurrentProcess which returns object of Process class. If we would like to return IProcess we would have to return here ProcessWrap instance or any other class implementing IProcess that would have to be created.
This would make the code a little bit more complicated. Although there are benefits for returning IProcess here, I believe that in majority of cases current implementation should be enough.

If someone would see benefits for himself having IProcess being returned I'm happy to implement it. For our needs it's enough to just return Process object

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this library is test-ability of the code and easy mocking. If the return value cannot be mocked, there is no point in implementing this API in this library.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed approach. I introduced IProcessFactory that is responsible for creating IProcess object. So basically all Process static methods are placed there.
Now we are able to return IProcess instead of Process

/// </summary>
/// <param name="processId">The system-unique identifier of a process resource.</param>
/// <returns>A System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter.</returns>
Process GetProcessById(int processId);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return the IProcess interface to allow proper mocking.

/// <param name="processId">The system-unique identifier of a process resource.</param>
/// <param name="machineName">The name of a computer on the network.</param>
/// <returns>A System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter.</returns>
Process GetProcessById(int processId, string machineName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return the IProcess interface to allow proper mocking.

@jozefizso
Copy link
Owner

Please, include also unit tests for newly implemented methods.

@phillbee
Copy link

phillbee commented Jun 4, 2019

Are there any plans to merge this?

Copy link
Owner

@jozefizso jozefizso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, include unit and/or integration tests for newly implemented methods.

@jozefizso
Copy link
Owner

The code is missing tests so it wasn’t merged yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants