Design a site like this with WordPress.com
Get started

Working with Power Automate

The power of no-code, low-code programming.

Have you ever heard of low code or no-code environments? It’s where you can create an application or a process visually without having to know a programming language. If you are familiar with IFTTT, then you will understand. Power Automate from Microsoft is one of those tools that we use at work.

Power Automate (formally known as Flow) is an exciting tool in that it is flexible and has a ton of connectors that integrate to a lot of services. Most connectors are free, but some are premium services (cost money). See for yourself; I’m sure you can find something to connect to.

Creating a flow visually is very similar to creating a flow chart, except that each element has actual code behind it. You have all (or most) of the features of a programming language. Factors include input, output, case statement, variables, if-then conditions, loops, etc.

Simple Approval Workflow

I use it primarily for managing approval workflows for my applications. I would instead create a flow visually than wire one up in code. It is easier to see what is going on and make changes. The process runs in the cloud, and I can communicate to and from with it via HTTP service calls.

I can send notifications to email or Microsoft Teams within the flow, or both. I have my flows send me alerts to our Teams channel if something went wrong or emails to the application owner with updates to the workflow. It’s pretty nice.

Besides workflows, I use Power Automate to run various things on a schedule. It’s easy to do scheduled tasks like hitting an API endpoint every Monday morning at 7 am so that a report is run and results sent out. Or to check to see if specific Flows are still active and, if not, turn them back on (Microsoft has a habit of turning off Flows due to inactivity). My favorite is the “I got an email from the Boss Alerts” type of Flow that I created for myself.

There are a few downsides that, like everything else, I don’t like l. There is no CI/CD pipeline to push changes to a Production environment. I have to make the changes manually.

There is no code repository either, so there is no version history. If you want a version history, you have to manually create an export and save that somewhere. It’s a manual process in need of automating.

Overall, Power Automate has been a positive experience for me. There have been issues that I have gotten stuck on, but the community forum is a good source of knowledge to search for or to post a question. I like it and want to find more uses cases for it.

Drop me a comment if you tried Power Automate and tell me what you think.

Happy Coding!

Advertisement

Visual Studio 2022 Tools I use

I use several Visual Studio extensions when I’m coding. Here is what I got.

Visual Studio has been my developing environment since the 2015 community edition and I really like it. I enhanced it with several extensions that I liked kept them through the visual studio iterations to what I use now, Visual Studio 2022. Some are no longer available for 2022 but most of them are. These are the tools that I like to use.

I choose it because I use it

That’s from an old Mastercard commercial with Robert Doval but it applies here as well. I installed these tools because I found them useful and saved me from some potentially embarrassing moments.

Let’s start with a must-have tool, a Spelling checker. Yes, the humble spelling checker saved my bacon many times. I’ve been using a spelling checker ever since a client pointed out spelling errors on one project review. Luckily the project was still in the Test environment and not Production but it was embarrassing to sit through the meeting with multiple typos jumping for attention.

I use the Visual Studio Spell Checker because it works and it is free. Be sure to get the right version that matches the Visual Studio version that you are using. Use the above link to find the one you need.

The other tool that I use is actually a collection of several tools all in one package. Now you can install the package get all of them or you can pick and choose and install only what you need. As for me, I install all of them as they do come in handy. Productivity Power Tools is the one I’m talking about.

Depending on what version of Visual Studio you have the list of tools changes. Seems like the 2015 version has the most tools and the 2022 version has the least but that is not necessarily a bad thing. After all these extensions were designed to plug any shortcoming of the IDE and each new version of Visual Studio would probably incorporate some of these tools.

My Favorites

My all-time favorite in this tool package is Align Assignment. If you are OCD in any sense this is a must. Usually, you have a block of code where you are just doing assignments and it’s all ragged. I hate that!

Before Assignment Align
After Assignment Align

This is music to my eyes; it’s only a couple of clicks to highlight the block and then a simple keyboard command to align everything. This works in c# as well as Javascript.

My other favorite is the Solution Error Visualizer. This extension adds the red squiggly lines under the filename that has an error in the Solution Explorer. Now you can see at a glance where the errors are located at.

Solution Error Visualizer at work

It’s a simple tool that serves up helpful information at a glance. No keystrokes or clicks to perform; it’s just there.

Well, there you have it. A few Visual Studio extensions that I use on a regular basis to tidy up my work and help me troubleshoot. These tools are available for all versions of Visual Studio for Windows.

Drop me a comment if you use these or any other tools. I would like to hear what you are using.

Unit Test Progress

My second attempt at Unit Testing for my application. Was I successful?

My first attempt at unit testing didn’t go so good. Well, not at all. I wasn’t able to do a thing other than to create a new project to contain the unit testing. I had two great videos that I was following but when it came to mocking the data it fell apart. I couldn’t make heads or tails of how to mock because of the way I did the methods in the controllers. Out of frustration, I abandoned unit testing until fixed my fat controllers.

On my last blog, Fat Controllers: Going on a Diet, I talked about how I watched a course on what I consider best programming practices. One of the topics covered was the separation of business logic from the controller. Using that knowledge I reworked a controller dealing with several reports to a service model. With that service in place, I felt it was time for another crack at unit testing and MOQ.

My last attempt at unit testing dealt with the MOQ aspect of things. I couldn’t figure out how to hook a MOQ to my database connections. Now that I have an IReportProverder service setup, it was easier to follow the videos.

Speaking of videos, I have been watching two different videos on using MOQ in unit testing. One introduces Autofac in testing and the other doesn’t. I’m not entirely sure what Autofac does so I skip that part of the tutorial and jump to the other video to continue. Both have the same concept but just go about it differently.

The two videos that I recommend to watch are Mocking in C# Unit Tests – How To Test Data Access Code and More by Tim Corey and Unit Testing: MOQ Framework by the Microsoft Visual Studio YouTube channel. Both tutorials use xUnit as the testing framework. The Microsoft Visual Studio has four videos on unit testing that are fantastic.

For the unit test framework, I started with MSTEST but switched to xUnit simply because all the tutorials I’ve seen were using xUnit. I’m sure if you learn one, you can learn the other.

Since I’m using the .NET Framework I had to do some tweaks to xUnit to get it working. The xUnit documentation says that you have to use the .NET Core template when you create your test project but then make a change to the project file. It’s not a difficult change, just change the target framework from the current version to that of what you are using. In my case, it’s version 4.5.2.

FROM:
<TargetFramework>net5.0</TargetFramework>

TO:
<TargetFramework>net452</TargetFramework>

One last configuration I had to do was to set the project reference. Without that reference, it would have a build error. It was simple enough to do. Right-click on the project name and select Add, Project Reference, then check the main project you are working on. That’s it. I can now start creating unit tests.

using colttdb.Controllers;
using colttdb.Models;
using colttdb.Providers;
using Moq;
using System;
using System.Collections.Generic;
using Xunit;

namespace colttdb.Tests
{
    public class ReportsProvider
    {
        [Fact]
        public void GetAllCoursesbyTerm_validList()
        {
            // Arrange
            string Term = "FALL 2022";
            var mock = new Mock<IReportsProvider>();
            mock.Setup(x => x.GetAllCoursesbyTerm(Term)).Returns(GetSampleAllCourses());
            var controller = new ReportsController(mock.Object);
            var expected = GetSampleAllCourses();

            // Act
            var actual = controller.GetAllCoursesByTerm(Term);

            // Assert
            Assert.True(actual != null);
            Assert.Equal(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.Equal(expected[i].Term_Desc, actual[i].Term_Desc);
                Assert.Equal(expected[i].AboutProfessor, actual[i].AboutProfessor);
                Assert.Equal(expected[i].Department, actual[i].Department);
                Assert.Equal(expected[i].AccessibilityAlly, actual[i].AccessibilityAlly);
                Assert.Equal(expected[i].AccessibilityVideoCaptions, actual[i].AccessibilityVideoCaptions);
                Assert.Equal(expected[i].BasedOn, actual[i].BasedOn);
                Assert.Equal(expected[i].BlackBoardTemplate, actual[i].BlackBoardTemplate);
                Assert.Equal(expected[i].CourseCopiedById, actual[i].CourseCopiedById);
                Assert.Equal(expected[i].Class_CRN, actual[i].Class_CRN);
                Assert.Equal(expected[i].Camp_Code, actual[i].Camp_Code);
                Assert.Equal(expected[i].Citations, actual[i].Citations);
                Assert.Equal(expected[i].Class_Number, actual[i].Class_Number);
                Assert.Equal(expected[i].Class_Section, actual[i].Class_Section);
                Assert.Equal(expected[i].Class_Subject, actual[i].Class_Subject);
                Assert.Equal(expected[i].College, actual[i].College);
                Assert.Equal(expected[i].Contacted, actual[i].Contacted);
                Assert.Equal(expected[i].ContentStructure, actual[i].ContentStructure);
                Assert.Equal(expected[i].Deleted, actual[i].Deleted);
                Assert.Equal(expected[i].Faculty_Oid_Rgv, actual[i].Faculty_Oid_Rgv);
            }
        }

        private List<Course> GetSampleAllCourses()
        {
            List<Course> output = new List<Course>
            {
                new Course
                {
                    Id = 1,
                    Term_Desc = "FALL 2021",
                    Deleted = false,
                    InstructionalDesigner = "ray.garza@utrgv.edu",
                    CourseCopiedById =  "Yes",
                    Faculty_Oid_Rgv = "user1@utrgv.edu",
                    AboutProfessor = "Yes"
                },
                 new Course
                {
                    Id = 2,
                    Term_Desc = "FALL 2021",
                    Deleted = false,
                    InstructionalDesigner = "ray.garza@utrgv.edu",
                    CourseCopiedById =  "Yes",
                    Faculty_Oid_Rgv = "user1@utrgv.edu",
                    AboutProfessor = "Yes"
                },
                  new Course
                {
                    Id = 3,
                    Term_Desc = "FALL 2021",
                    Deleted = false,
                    InstructionalDesigner = "Marilu.Reyes@utrgv.edu",
                    CourseCopiedById =  "Yes",
                    Faculty_Oid_Rgv = "user1@utrgv.edu",
                    AboutProfessor = "Yes"
                },
                   new Course
                {
                    Id = 4,
                    Term_Desc = "FALL 2021",
                    Deleted = false,
                    InstructionalDesigner = "Marilu.Reyas@utrgv.edu",
                    CourseCopiedById =  "Yes",
                    Faculty_Oid_Rgv = "user1@utrgv.edu",
                    AboutProfessor = "Yes"
                },
                    new Course
                {
                    Id = 5,
                    Term_Desc = "FALL 2021",
                    Deleted = false,
                    InstructionalDesigner = "Christopher.Jazinski@utrgv.edu",
                    CourseCopiedById =  "Yes",
                    Faculty_Oid_Rgv = "user1@utrgv.edu",
                    AboutProfessor = "No"
                },
            };
            return output;
        }
    }
}

The above code is my unit test that checks a method that gets all courses with a given term. The Arrange is where I do all the setting up and assigning the mock data. Down at the bottom is a sample list of courses that I mocked to act as the database.

Next is the Act where I call the method in the controller which runs through the process of getting the data but not from the database but from the mock that I created (GetSampleAllCourses()).

Finally, the Assert section is where I do all the checking. In this case, I check to see if something was actually returned. If it is null, then something is wrong. Then I count the number of records retrieved against what is expected. Finally, I use a loop to run through all the records in the list and check each field is the same as expected.

How detailed the checks you perform is up to you as the developer. There may be requirements that you have to follow, or there might be time constraints that limit how much testing can be developed. As I continue to learn all about testing and I’m sure my thoughts on this will change.

One last topic I like to touch on is mocking. Personally, I love the concept of mocking data. I can set up various scenarios with known data with mocks and reuse it over and over without messing with an actual database. It’s a win-win situation.

Finally figuring out how to do unit testing has a very satisfying feel to it. Unit testing along with putting my fat controllers on a diet via services are new tools that I can put in my toolbelt and feel confident that I am becoming a better developer. Baby steps.

Laptop Upgrade and Coding Environment Issues

Upgrading my laptop to M1 Apple presents a challenge to create a Windows coding environment to use.

I am a proud owner of the new Apple M1 MacBook Pro 16” laptop. Well, it’s on order. I should get it sometime in March so, that gives me time to setup a working Windows environment and have Visual Studio installed. But I have a problem.

Why is that an issue? I got Parallels to load Windows on. Long story short, running the Intel version of Windows on M1 is not a good idea. Was I caught off guard with this issue? No, I had plans to resolve the problem by Remoting into the Dell laptop that the University provided.

I planned to RDP into the University laptop from my M1-based Apple Mini and MacBook, but I ran into a problem. That laptop is configured not to remote into it and has a group policy that prevents me from turning on RDP. Well, there goes that idea.

My next option is to use my Ubuntu Mac Mini (I have two Mini’s) and install a Windows VM. I am currently using it for my Homebridge server, and having a Windows VM wouldn’t be much of an issue. That seemed like a good idea until I checked the memory on it. It only had 8 Gb of RAM, which is the maximum allowed for that mini. Allocating six gigs of RAM for the VM for Windows 10 didn’t sound like a good idea. So ok, I need something else.

I remembered that I have my old 27″ Mac that I planned on trading in for a gift card. That will work perfectly since it has plenty of RAM and hard drive space. So I downloaded Windows 10 and got a product key from my visual studio subscription. I now had a computer that I could RDP into and do my work.

During RDP setup, I saw a link saying that opening up a port is a security risk to your internal network. It suggested that I should connect via a VPN instead. That sounded like a good idea.

I created an OpenVPN Cloud free account and got my Windows developing environment as a Host RDP Server and my other M1 Apple computers as the clients. Bingo Bango, it all works now. I can now continue to go to my favorite coffee shop, Jitterz, remote into my Windows machine and continue coding.

Well I thought all was good until I tried to VPN into work. While it connected, network traffic wasn’t going through it since traffic is going through the OpenVPN connection. I’m not sure if I can tunnel into the computer and direct university traffic through their VPN.

I’m sure there is a way to do that but it is beyond my skill set. I’m back to the open the RDP port on my router.

I’m sure there were better ways of resolving my issue, but it gave me something to do over the weekend, and now I am a happy camper. Happy Coding!

Fat Controllers: Going on a Diet

After watching a training video I learn something new that will make me a better developer.

In my quest to be a better developer, I watched a video in LinkedIn Learning called ASP.NET MVC: Building for Productivity and Maintainability by Jess Chadwick and was impressed with what he taught. One of the main topics I got from this is that my controllers are fat. Very fat. In fact, they need to go on a diet big time.

My controllers had everything including the kitchen sink in them. It worked but it was getting hard to follow the logic flow. Even worse, if I had to come back to do maintenance it took a while to relearn what I was doing. Jess taught me how to separate business logic from the controller using services.

Why hadn’t I been doing this stuff from the beginning? Well, simply put, I wasn’t taught to write code that way. Besides my Computer Science classes in college, I was self-taught on c# and the .NET MVC Framework. All those tutorials on video or books never covered the best practices in coding. Now, after watching this video, I know better.

I had a project that I am working on that had a couple of reports that felt was a good candidate to try out this system of services. I figured out how to wire it up and create the service provider and then the corresponding service. Then created the method in the controller to use the service.

I already had a fat method from one report so I converted that to use a service. Now the controller has two methods with about ten lines each that are easy to follow. Nice and slim and all the business logic separated in a service. I really like this system.

Another benefit in using services is Unit testing. It will be a lot easier to do a Unit test against the services rather than against a fat controller. I tried learning to do Unit testing against my fat controller and I ended up giving up. I couldn’t figure out how to do it but now, with services, I can see it will be a lot easier to do.

If I had time, I would redo all of the controllers for my project but unfortunately, I don’t. I’m not giving up. Any chance I have I’ll continue to put my fat controllers on the diet. Any new project and I will definitely be using the new method. I feel I have progressed as a developer and that is good.

Has anyone else seen the video? If so, tell me what you learned from it.

Happy coding everyone!

Azure DevOps is my Favorite Tool

I don’t know about anyone else, but I have always liked Azure DevOps since we moved to it. It has everything a developer needs. Our GitLab account had everything we needed to hold our repositories. However, we didn’t know how to take advantage of its CI/CD pipeline. I also used Asana to manage my projects and their numerous tasks. I loved Asana, but it was external to GitLab’s. I was constantly juggling websites to get my work done. It was getting tedious, and I forgot things. Something had to change.

I was excited to learn that we were moving to Azure and Azure DevOps. It has all I need, ways to manage your repository, CD/CI, tests, tasks, boards, wiki, and integration to everything Microsoft (at least to Teams and Visual Studio). With some training classes and lots of experimenting, we flow from local to Development, Test, and Production instances.

What I like about Azure DevOps are the boards. I love that I can track and update tasks. My boss can add tasks and see where I’m at without bugging me with a status update. I can also post questions to my boss about a particular task, responding to it. It’s all stored on the board and not email. Goodbye to lost in email hell. Fantastic!

I now figured out how to see and update those same tasks within Visual Studio 2022. The only thing I have not figured out is how to tag someone in a conversation. For example, I would use the @ symbol on the DevOps and start typing the user’s name. It would IntelliSense the correct contact and fill it in, but in Visual Studio, it doesn’t seem to have that feature. Perhaps a future update will have it.

Now not every team member likes using the system. They want to code and push their changes and that’s it. They are not into Kaban boards and wiki’s for documenting their web apps. What a shame. I think it makes you a better developer. All I can say is that I love it!

By the way, you can get a free account to learn Azure and Azure DevOps. I encourage you to check it out and give it a try.

The Benefits of Logging Your Code

As a junior developer, I am constantly looking to implement coding best practices in my routine and pass along what I’ve found to the development team that I’m in. Logging was one of them.

I noticed that no one was using any logging other than console output. While that is fine while developing the Web App, it’s not practical in a production environment. The last thing you want to do is ask the client to open up developer mode on the browser to get some data written to the console. Believe me, that is a bad idea.

You can use a slew of tools to add logging to your code. For me, I chose NLog as my tool of choice, dumping all of the data onto our Splunk account. I also set up Splunk to alert me if NLog recorded any error events. These alerts give me a heads up before the client contacts me about an issue.

Those error alerts already have come in handy. I received one from one of my web apps and with the alert information, I was able to create a support ticket on behalf of the web app owner, putting it in my queue.

When I had the time to work on the issue, I am able to duplicate it in the test environment and gather additional log information to narrow down the root cause. You don’t know how much of a time saver it is to not only log the error traps but certain data such as variables and objects. It gives a complete picture of what is going on and what you need to do to fix the bug.

Another thing that I did was to create a template for NLog for others in my team to use. All they have to do is fill in their name, email, and application name. All of that along with the error is used in Splunk to send out the email alerts to the team leader and to the developer of the application. The boss likes it because it keeps him in the loop.

I’m sure there are newer ways of analyzing errors in real-time with application insights but that is down the road. Right now, what we have is working. What logging system are you using? Do you like it? Let me know in the comments.

My To-Do List

My coding to-do list.

Being my first job as a programmer, I’ve come a long way in my skills. I still consider myself a junior programmer compared to the rest of the world. I am cognate that should be using best practices when developing a Web App. That is why I have made a to-do list to get me in that position I feel I should be at.

So, without further delay here is my list.

  • Use services to separate business logic from controllers
  • Once services are implemented, work on Unit testing
  • Implement MOQ to supplement Unit testing
  • Use EF to connect to Oracle databases
  • Figure out how to do a DAST security can from Azure DevOps CI/CD pipeline.

It’s a small list but it’s essential for me to master it in order to construct my applications in a readable and manageable fashion. We are a young development team in the same boat as me where I work. We all need to up our skills to produce better code at a quicker pace.

Not included on the list but ongoing are improvements in accessibility in all of our applications. Our application needs to be user-friendly for anyone that uses it, including those with disabilities.

I am constantly discussing accessibility issues or best practices with my boss. I also reach out to the developers of some of the technology I use and ask if they have plans to improve accessibility. Hopefully, I can nudge them in that direction.

Out of the list I provided, I would say that the top three items are high on my list. If I can master those three tasks, that will go a long way in improving my code. I can then document and teach the others in my team how to do the same.

What’s on your list? Add your list to the comments and explain why you chose them.

Cheers, and happy coding.

COVID Fallout

I work at the local University as a Software and enjoy the atmosphere there. Students shuffling from one class to the next, co-workers out doing their lap around campus, and the squirrels busy hunting for food. Even though my office was a little warm, I could easily step out and wander the halls for a brief recess. There were many exciting applications to create and departments to collaborate with. As far as I was concerned, life was good on campus.

All of that came to a screaching halt when the threat COVID-19 swept the University. Within a week we were all booted out and working from home. Life had changed.

Working from home was an adjustment but it turned out it was not that hard of a change. Even though I lost a lot of the benefits from working on campus, I gained many other perks. Perks such as cutting an hour of driving time, sleeping later due to not having to drive to work, new standing desk, and I get to see my two cats all day long.

Another perk is the use of my laptop anywhere I want. I could code anywhere other than home. Lately, I would hop on my bike and pedal over to the local coffee shop and work there. In fact, I’ve been riding my bike a lot more. I’ll ride over to the coffee shop to work, head out to lunch, and finish the afternoon working at home. What a way to work! I do miss the squirrels though. They were fun to watch.

A year later, the campus has gone to a hybrid learning model. It’s a combination of on-campus classes mixed with online learning. The Information Technology (IT) department has mostly stayed as work from home permanently. We programmers can work anywhere with a computer and Internet access. I think we were well prepared for work from home. Our job, correspondence, timekeeping, meetings, and project assignments were already done online. It wasn’t a big stretch to start working from home for us.

Thanks for reading my initial post. I haven’t figured the details out yet, but I know it will be coding-related.